Wednesday, 15 April 2015

Get Value of hidden column of radgrid telerik in asp.net -


I have a radridge in which I hide the ID column. Now I want to get its value on linkbutton click. If the column appears, then it works fine but

it shows empty values ​​when it is invisible. My code is

  protected zero RadGrid1_ItemCommand (object sender, Telerik.Web .UI.GridCommandEventArgs e) {if (e.CommandName == "detail") {GridDataItem dataItm = e.Item as GridDataItem; String Value = Data ITM ["ID"]. Text; }}    

Please try with the code snippet below.

ASPX

  & lt; Telerik: RadGrid id = "RadGrid1" runat = "server" AutoGenerateColumns = "false" OnNeedDataSource = "RadGrid1_NeedDataSource" OnItemCommand = "RadGrid1_ItemCommand" & gt; & Lt; MasterTableView DataKeyNames = "ID" & gt; & Lt; Columns & gt; & Lt; Telerich: Gridbound column datafield = "id" unique name = "id" header text = "id" & gt; & Lt; / Telerik: GridBoundColumn & gt; & Lt; Telerich: Gridbound column datafield = "id" unique name = "id1" header text = "id" visible = "wrong" & gt; & Lt; / Telerik: GridBoundColumn & gt; & Lt; Telerich: Gridbound column datafield = "id" unique name = "id2" headerText = "id" display = "wrong" & gt; & Lt; / Telerik: GridBoundColumn & gt; & Lt; Telerik: GridTemplateColumn & gt; & Lt; ItemTemplate & gt; & Lt; ASP: Button ID = "Button1" runat = "Server" commandname = "Extension" CommandArgument = '<% # Eval ("id")% & gt; / & Gt; & Lt; / ItemTemplate & gt; & Lt; / Telerik: GridTemplateColumn & gt; & Lt; / Column & gt; & Lt; / MasterTableView & gt; & Lt; / Telerik: RadGrid> Protected Zero RadGrid1_NeedDataSource (Object Sender, GridNeedDataSourceEventArgs E) {dynamic data = new [] {new {id = 1, name = New {id = 5, name = "NAME2"}, new {id = 2, name = "NAME2"}, new {id = 3, name = "NAME3"}, new {id = 4, name = "NAME4"}, new {id = 5, Name = "name 5"}}; RadGrid1.DataSource = Data; } Zero RadGrid1_ItemCommand (object sender, GridCommandEventArgs e) protected {if (e.CommandName == "extension") {GridDataItem item = e.Item as GridDataItem; String strID = item.GetDataKeyValue ("ID") ToString (); // We can get value of the id field here string strID1 = item ["ID1"]. Text; // We are not able to get the value of the ID field here because the column view is false string strID2 = item ["ID2"]. Text; // We can get value of the id field here strCommandArgument = e.CommandArgument.ToString (); // We are able to get the value of the ID field here}   

Please use the Display property in place of displayed property Please.

No comments:

Post a Comment