我有一个下拉列表和一个gridview外的按钮,用于控制要在gridview中显示的数据。另外,我在gridview中进行了“编辑”。单击gridview中的“编辑”后,如何保留下拉列表和gridview数据的值?
<asp:DropDownList ID="ddl" runat="server">
<asp:ListItem>All</asp:ListItem>
<asp:ListItem>Yes/asp:ListItem>
<asp:ListItem>No</asp:ListItem>
</asp:DropDownList>
<asp:Button ID="btn" runat="server" Text="Search" onclick="btnOnClick" />
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
OnRowEditing="gvUpdateMsg_Rowediting" OnRowUpdating="gvUpdateMsg_Rowupdating"
OnRowCancelingEdit="gvUpdateMsg_Cancelingedit">
<Columns>
<asp:TemplateField ShowHeader="False">
<EditItemTemplate>
<asp:LinkButton ID="btnUpdate" runat="server" CausesValidation="True" CommandName="Update"
Text="Confirm"></asp:LinkButton>
<asp:LinkButton ID="btnCancel" runat="server" CausesValidation="False" CommandName="Cancel"
Text="Cancel"></asp:LinkButton>
</EditItemTemplate>
<ItemTemplate>
<asp:LinkButton ID="btnEdit" runat="server" CausesValidation="False" CommandName="Edit"
Text="Reply"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
........
</ItemTemplate>
</asp:TemplateField>
.......
</Columns>
</asp:GridView>
答案 0 :(得分:0)
将“OnClick”事件添加到您的btnEdit按钮,如下所示:
<asp:LinkButton ID="btnEdit" runat="server" CausesValidation="False"
CommandName="Edit" Text="Reply" OnClick="btnEdit_Click"></asp:LinkButton>
在背后的代码中:
protected void btnEdit_Click(object sender, EventArgs e)
{
GridViewRow clickedRow = ((LinkButton)sender).NamingContainer as GridViewRow;
LinkButton btnEdit = (LinkButton)clickedRow.FindControl("btnEdit");
string any_data_for_gridview = clickedRow.Cells[1].Text; //change number 1
string any_data_for_ddl = ddl.SelectedValue.ToString();
}