[英]select only one checkbox in gridview and edit that checked row
i have a gridview and which has one column as the asp checkbox control and i want the user can check one check box and click on the edit button to edit that perticular row 我有一个gridview,其中有一列作为asp复选框控件,我希望用户可以选中一个复选框,然后单击“编辑”按钮以编辑该垂直行
my code for this is 我的代码是
<asp:GridView runat="server" CssClass="width" ID="gvGrades" AutoGenerateColumns="false" ShowHeader="true" OnRowCancelingEdit="gvGrades_RowCancelingEdit" OnRowCommand="gvGrades_RowCommand" OnRowDataBound="gvGrades_RowDataBound" OnRowEditing="gvGrades_RowEditing" OnRowUpdated="gvGrades_RowUpdated" OnRowUpdating="gvGrades_RowUpdating" OnRowDeleting="gvGrades_RowDeleting">
<Columns>
<asp:TemplateField>
<HeaderTemplate>
Select
</HeaderTemplate>
<ItemTemplate>
<asp:CheckBox ID="chkSelect" class="asp" runat="server" />
<asp:Label ID="lblId" runat="server" Text='<%# Bind("id") %>' Visible="false"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<HeaderTemplate>
Grade Name
</HeaderTemplate>
<ItemTemplate>
<asp:Label ID="lblName" runat="server" Text='<%# Bind("grade_name") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<HeaderTemplate>
Organization Name
</HeaderTemplate>
<ItemTemplate>
<asp:Label ID="lblOrganizationName" runat="server" Text='<%# Bind("organization_name") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<HeaderTemplate>
Minimum Basic Salary
</HeaderTemplate>
<ItemTemplate>
<asp:Label ID="lblSalary" runat="server" Text='<%# Bind("min_basic_salary") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton runat="server" ID="lnkDelete" CommandName="Delete" Text="Delete"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton runat="server" ID="lnkEdit" CommandName="Edit" Text="Edit"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</fieldset>
</ContentTemplate>
</asp:UpdatePanel>
<asp:Button Text="Add" Width="70px" ID="btnAdd" runat="server" OnClick="btnAdd_Click" />
<asp:Button Text="Edit" ID="btnEdit" Width="70px" runat="server" OnClick="btnEdit_Click"
/>
Please provide code for edit button click also 请同时提供代码以供编辑按钮点击
thanks 谢谢
use can use GridView.SelectedIndexChanged Event. 使用可以使用GridView.SelectedIndexChanged事件。
you might do something like this 你可能会做这样的事情
<asp:TemplateField >
<ItemTemplate>
<asp:CheckBox ID="chb1" AutoPostBack="true" runat="server" />
</ItemTemplate>
</asp:TemplateField>
and you can set the edit fied enable=false
and in the postback you can set enable=true
您可以设置edit fied
enable=false
,在回发中可以设置enable=true
protected void GVSelectedIndexChanged(object sender, GridViewRowEventArgs e)
{
var check = (CheckBox) e.Row.FindControl("chb1");
if(check != null)
{
// do something
}
}
Follow the below steps for enable edit button without postback [using javascript] 请按照以下步骤启用编辑按钮,而无需回发[使用javascript]
Register OnRowDataBound event of Gridview. 注册Gridview的OnRowDataBound事件。
Find the checkbox and Edit button using the itemindex [in Onrowbound event] 使用[在Onrowbound事件中] itemindex查找复选框和“编辑”按钮
After finding checkbox, register javascript function onchange event with parameter [of Edit button Id] 找到复选框后,使用[编辑按钮ID]的参数注册javascript函数onchange事件
Then you will get the Edit button in javascript 然后,您将在javascript中获得“编辑”按钮
Put the javascript enable code. 放入javascript启用代码。
Let me know if you have any problem or query. 让我知道您是否有任何问题或疑问。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.