querystring in datalist template. + asp.net2.0 +c#
-
i have a datalist template hyperlink..if i click on tat i have to pass a query string to the response page... the query string is a dynamic one... for eg if im displaying a user name n password in the datalist i have to pass userid as querystring of the corresponding selected username.. how can i do tat??\plz help me out.
-
i have a datalist template hyperlink..if i click on tat i have to pass a query string to the response page... the query string is a dynamic one... for eg if im displaying a user name n password in the datalist i have to pass userid as querystring of the corresponding selected username.. how can i do tat??\plz help me out.
Hi, I could not find any direct way to do this. But u can use ItemDataBound event of datalist. U need to put hyperlink in datalist ItemTemplate without setting its NavigateUrl property. This property u can set at runtime while datalist it bound to the datasource. Your hyperlink should be like following. I have put one label control which will have the value which we want make querystring. I have set its visible property = false; now I am setting hyperlink's navigateurl property in ItemDataBound event of datalist. protected void dlst_ItemDataBound ( object sender, DataListItemEventArgs e ) { HyperLink hl = ( HyperLink )e.Item.FindControl( "HyperLink1" ); Label lbl = ( Label )e.Item.FindControl( "lblusernamehidden" ); if ( hl != null && lbl != null ) { hl.NavigateUrl = "~/TargetPage.aspx?username=" + lbl.Text; } } this way you can get querystring dynamically in hyperlink. also set Datalist's OnItemDataBound property to "dlst_ItemDataBound". I hope this will help you. Thanks and Regards, Chetan Ranpariya
-
Hi, I could not find any direct way to do this. But u can use ItemDataBound event of datalist. U need to put hyperlink in datalist ItemTemplate without setting its NavigateUrl property. This property u can set at runtime while datalist it bound to the datasource. Your hyperlink should be like following. I have put one label control which will have the value which we want make querystring. I have set its visible property = false; now I am setting hyperlink's navigateurl property in ItemDataBound event of datalist. protected void dlst_ItemDataBound ( object sender, DataListItemEventArgs e ) { HyperLink hl = ( HyperLink )e.Item.FindControl( "HyperLink1" ); Label lbl = ( Label )e.Item.FindControl( "lblusernamehidden" ); if ( hl != null && lbl != null ) { hl.NavigateUrl = "~/TargetPage.aspx?username=" + lbl.Text; } } this way you can get querystring dynamically in hyperlink. also set Datalist's OnItemDataBound property to "dlst_ItemDataBound". I hope this will help you. Thanks and Regards, Chetan Ranpariya