本文介绍了将gridview的selecteditem值作为字符串传递给另一个页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我的gridviews的OnrowDataBounding,OnselectedIndexchanged事件正常工作。选择控件后,按预期传递给另一个页面,但即使在调用页面和details.aspx页面中,selectedindex datakey值也为null。我喜欢将此selectedindex值传递给字符串,从而在详细信息页面中使用查询字符串。请帮我正确编码。 我也按照http://www.codeproject.com/Questions/103062/How-to-get-the-value-of-a的建议尝试过-selected-in-gridview 我的代码如下 My gridviews's OnrowDataBounding, OnselectedIndexchanged events working ok. after selecting control is passing to another page as intended, but selectedindex datakey value is null even in calling page and in details.aspx page. I like to pass this selectedindex value to a string and thereby use in querystring in details page. please help me out with correct coding. I have also tried as suggested at http://www.codeproject.com/Questions/103062/How-to-get-the-value-of-a-selected-row-in-gridview My code is as follows<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns = "False" AllowPaging="true" OnPageIndexChanging="gdv1_OnPaging" PageSize="5" DataKeyNames = "Material" OnRowDataBound = "gv1_OnRowDataBound" OnSelectedIndexChanged = "gv1_SelectedIndexChanged" CSSClass= "~/Styles" EnableViewState="False" PagerSettings-Mode="Numeric" AutoGenerateSelectButton="true"> protected void gv1_OnRowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { e.Row.Attributes["onclick"] = Page.ClientScript.GetPostBackClientHyperlink(GridView1, "Select$" + e.Row.RowIndex); e.Row.ToolTip = "Click to select this row."; } }protected void gv1_SelectedIndexChanged(object sender, EventArgs e) { int selectedIndex = GridView1.SelectedIndex; string selectedMaterial = (GridView1.DataKeys[selectedIndex]).Value.ToString(); Server.Transfer("Details.aspx"); }//code in details.aspx protected void Page_Load(object sender, EventArgs e) { if (this.Page.PreviousPage != null) { GridView GridView1 = GridView)this.Page.PreviousPage.FindControl("GridView1"); int selectedIndex = GridView1.SelectedIndex; string selectedMaterial = (GridView1.DataKeys[selectedIndex]).ToString();} 我的尝试: What I have tried://int selectedIndex = Convert.ToInt32(GridView1.SelectedDataKey[1].ToString()); int selectedIndex = GridView1.SelectedIndex; string customID = (GridView1.DataKeys[selectedIndex]["pkCityId"]).ToString(); 推荐答案 我的尝试: What I have tried://int selectedIndex = Convert.ToInt32(GridView1.SelectedDataKey[1].ToString()); int selectedIndex = GridView1.SelectedIndex; string customID = (GridView1.DataKeys[selectedIndex]["pkCityId"]).ToString(); <asp:gridview id="GridView1" runat="server" autogeneratecolumns="False" allowpaging="true" OnPageIndexChanging="gdv1_OnPaging" PageSize="5" DataKeyNames = "Material,pkCityId" OnRowDataBound = "gv1_OnRowDataBound" OnSelectedIndexChanged = "gv1_SelectedIndexChanged" CSSClass= "~/Styles" EnableViewState="False" PagerSettings-Mode="Numeric" AutoGenerateSelectButton="true"</asp:gridview> 亲切的问候Kind Regards 这篇关于将gridview的selecteditem值作为字符串传递给另一个页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-20 09:06