ASP.NET - sending multiple parameters in hyperlink column (navigateurl) dynamically  ASP.NET - sending multiple parameters in hyperlink column (navigateurl) dynamically

Asked By Joe Black
29-Dec-09 02:54 AM

hi,

i ahve a datagrid in which i am passing parameters from hyperlink column

rightnow iam passing the hyperlink column value as parameter as (dynamically)

HyperLinkColumn hypercolumn = new HyperLinkColumn();

hypercolumn.Text = "Select";

hypercolumn.DataNavigateUrlField = "projno_v2";

hypercolumn.DataNavigateUrlFormatString = "../../Test/test1.aspx?Projectid={0}";

grid.Columns.Add(hypercolumn);

//Grid columns

BoundColumn column = new BoundColumn();

column.DataField = "col2";

column.HeaderText = "col2name";

grid.Columns.Add(column);

column = new BoundColumn();

column.DataField = "col3;

column.HeaderText = "col3name";

grid.Columns.Add(column);

i want other 3 bound columns also to be sent as parameters in the querystring with the hyperlink navigateurl

can anyone help me

sending multiple parameters in hyperlink column (navigateurl) dynamically  sending multiple parameters in hyperlink column (navigateurl) dynamically

29-Dec-09 03:18 AM

do like this,

Solution 1:

<asp:datagrid id="Datagrid3" runat="server" AutoGenerateColumns="False" BorderColor="black" 

       HeaderStyle-CssClass="tableHeader" ItemStyle-CssClass= "tableItem">
        <Columns>
                  <asp:TemplateColumn HeaderText="Order">
                      <ItemTemplate>
                         <asp:Hyperlink runat= "server" Text='<%# DataBinder.Eval(Container.DataItem,"ProductName").tostring%>' 
                          NavigateUrl='<%# "page.aspx?Name=" & DataBinder.Eval (Container.DataItem,"ProductName").tostring & _  
                          "&ProductID=" & DataBinder.Eval(Container.DataItem,"ProductID").tostring %>' ID="ProductName"/>  
  
                      </ItemTemplate>
                     </asp:TemplateColumn>                                    
         </Columns>
</asp:datagrid>

Solution 2:

concatenate your data where your retrieve

for example if sql

select (cola + colb) as concat

from .....

 

if is business object add calculated property

string Concat

{

    get {return filelda + fieldb } 

 


Thanks and Regards,
http://www.codecollege.net/

re  re

29-Dec-09 03:43 AM

You could actually assing to the hyperlink column multiple column values as suggested http://bytes.com/topic/asp-net/answers/288413-multiple-elements-within-datagrid-querystring..

<asp:Hyperlink runat="server"
Text='<%#DataBinder.Eval(Container.DataItem,"Order ID")%>' NavigateUrl='<%#
"page.aspx?Orderid=" + DataBinder.Eval(Container.DataItem,"Orderid") +
"&ProductID=" + DataBinder.Eval(Container.DataItem,"ProductID")%>'
ID="Hyperlink1" NAME="Hyperlink1"/>

Re  Re

29-Dec-09 03:59 AM
In order to generate the HyperLink column's navigate URL dynamically with other column values as Query string parameters, the better approach is to use the ItemDataBound event of the DataGrid.

Below is the implementation of ItemDataBound event which will provide you a good help

protected void DataGrid1_ItemDataBound(object sender,DataGridItemEventArgs e) 
{
if(e.Item.ItemType == ListItemType.Item)
{
//Assuming cell 0 has the HyperLink column
HyperLink link = e.Item.Cells[0].Controls[0] as HyperLink
//Assuming the bound columns are cells 1, 2 & 3
link.NavigateUrl = string.Format("../../Test/test1.aspx?col1={0}&col2={1}&col3={2}", e.Item.Cells[1].Text, e.Item.Cells[2].Text, e.Item.Cells[3].Text);
}
}
i need to loop for all items  i need to loop for all items
30-Dec-09 01:57 AM

you gave me a good answer.

this is working for first link

if i want to loop for all rows (select options)how should i do that?

thanks for ur help

Re  Re
30-Dec-09 02:19 AM
Actually the ItemDataBound event will fire for each and every row in the DataGrid, so it shouldn't be an issue. This should work for all the rows.
Create New Account
help
Bold = "True" ForeColor = "#FFFFCC" BackColor = "#990000" > < / HeaderStyle> <FooterStyle ForeColor = "#330099" BackColor = "#FFFFCC" > < / FooterStyle> <Columns> <asp:BoundColumn DataField = "pubDate" HeaderText = "pubDate" > < / asp:BoundColumn> <asp:HyperLinkColumn DataNavigateUrlField = "link" DataTextField = "title" HeaderText = "Title" NavigateUrl = "link" > < / asp:HyperLinkColumn> < / Columns> <PagerStyle HorizontalAlign = "Center" ForeColor = "#330099" BackColor = "#FFFFCC" > < / PagerStyle> < / asp:DataGrid> All I did above text column assigned to the pubDate field of the datasource, and the other is a Hyperlink column with its DataNavigateUrl field assigned to the "link" column of the Data Source, and DataGridItemEventHandler( this .DataGrid1_ItemDataBound); this .Load + = new EventHandler( this .Page_Load); } #endregion private void DataGrid1_ItemDataBound( object sender, DataGridItemEventArgs e) { int i = e.Item.DataSetIndex; ListItemType it = e.Item.ItemType; if (it = = ListItemType.Item | | it = = ListItemType.AlternatingItem) { string strB = ( string )ds.Tables[2].Rows[i]["description"]; e.Item
correctly this is how it looks. private void datagrid_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e) { if ((e.Item.ItemType.ToString()) = = "EditItem") ((TextBox)(e.Item.Cells[1].Controls[0])).Width name: index] System.Web.UI.ControlCollection.get_Item(Int32 index) +58 gssquarantines.WebForm1.datagrid_ItemDataBound(Object sender, DataGridItemEventArgs e) in c: \ inetpub \ wwwroot \ gssquarantines \ quarantines.aspx.cs:197 System.Web.UI.WebControls.DataGrid.OnItemDataBound(DataGridItemEventArgs e) +110 System.Web.UI.WebControls.DataGrid.CreateItem(Int32 itemIndex, Int32 dataSourceIndex, ListItemType itemType, Boolean dataBind, Object dataItem, DataGridColumn[] columns, TableRowCollection rows, PagedDataSource pagedDataSource) +181 System.Web.UI FooterStyle> <Columns> <asp:EditCommandColumn ButtonType = "LinkButton" UpdateText = "Update" CancelText = "Cancel" EditText = "Edit"> < / asp:EditCommandColumn> <asp:BoundColumn DataField = "DateReceived" HeaderText = "Date Received"> < / asp:BoundColumn> <asp:BoundColumn DataField = "UnitManufacturer" HeaderText = "Unit Manufacturer"> < / asp:BoundColumn> <asp:BoundColumn DataField = "FirstName" HeaderText = "First Name"> < / asp:BoundColumn> <asp:BoundColumn DataField = "LastName" HeaderText = "Last
asp:TemplateColumn> <ItemTemplate> <asp:CheckBox id = "CheckBox1" runat = "server"> < / asp:CheckBox> < / ItemTemplate> < / asp:TemplateColumn> <asp:BoundColumn DataField = "ITEM_NO" HeaderText = "Item number"> < / asp:BoundColumn> < / Columns> [ / CODE] I've added the checkbox column using the template column. My primary key asp:TemplateColumn> <ItemTemplate> <asp:CheckBox id = "CheckBox1" runat = "server"> < / asp:CheckBox> < / ItemTemplate> < / asp:TemplateColumn> <asp:BoundColumn DataField = "ITEM_NO" HeaderText = "Item number"> < / asp:BoundColumn> <asp:BoundColumn DataField = "GCM" HeaderText = "GCM"> < / asp:BoundColumn> <asp:BoundColumn DataField = "TASK_OWNER" HeaderText = "Task owner"> < / asp:BoundColumn> <asp:BoundColumn DataField = "CHANGE_CATEGORY" HeaderText = "Change category"> < / asp:BoundColumn> <asp:BoundColumn DataField = "APPLICATION_IMPACTED" HeaderText = "Application
cellspacing = "0" id = "menu" border = "1" > <tr> <td style = "width:80px;" onmouseover = "showMenu('1');" > <asp:HyperLink runat = "server" ID = "hlkmen1" > One< / asp:HyperLink> < / td> <td style = "width:80px;" onmouseover = "showMenu('2');" > <asp:HyperLink runat = "server" ID = "hlkmen2" > two< / asp:HyperLink> < / td> <td style = "width:80px;" onmouseover = "showMenu('3');" > <asp HyperLink runat = "server" ID = "hlkmen3" > three< / asp:HyperLink> < / td> <td style = "width:80px;" onmouseover = "showMenu('4');" > <asp:HyperLink runat = "server" ID = "hlkmen4" > four< / asp:HyperLink> < / td> <td style = "width:80px;" onmouseover = "showMenu('5');" > <asp:HyperLink runat = "server" ID = "hlkmen5" > five