Gridview下拉菜单在Gridview\u编辑时填充[英] Gridview dropdown fill on Gridview_Editing

本文是小编为大家收集整理的关于Gridview下拉菜单在Gridview\u编辑时填充的处理方法,想解了Gridview下拉菜单在Gridview\u编辑时填充的问题怎么解决?Gridview下拉菜单在Gridview\u编辑时填充问题的解决办法?那么可以参考本文帮助大家快速定位并解决问题。

问题描述

嗨!

我正在编写代码以在 gridview 中编辑行,但我有一个查询.
我需要在版本中填写并选择我的下拉城市.
那么该怎么做呢?

<asp:GridView ID="gvAdmin"span> runat="服务器" AutoGenerateColumns="False" DataKeyNames="id"           CellPadding="4" ForeColor="#333333" GridLines="无" 宽度="100%" OnRowEditing="gvAdmin_RowEditing"           OnRowCancelingEdit="gvAdmin_RowCancelingEdit" OnRowDeleting="gvAdmin_RowDeleting"           OnRowUpdating="gvAdmin_RowUpdating"><AlternatingRowStyle BackColor="White" ForeColor="#284775" /><EditRowStyle BackColor="#999999" /><FooterStyle BackColor="#5D7B9D" Font-Bold="真" ForeColor="白色" /><HeaderStyle BackColor="#5D7B9D" Font-Bold="真" ForeColor="白色" Horizo​​ntalAlign="左" /><PagerStyle BackColor="#284775" ForeColor="白色" Horizo​​ntalAlign="Center" /><RowStyle BackColor="#F7F6F3" ForeColor="#333333" /><SelectedRowStyle BackColor="#E2DED6" Font-Bold="真" ForeColor="#333333" /><SortedAscendingCellStyle BackColor="#E9E7E2" /><SortedAscendingHeaderStyle BackColor="#506C8C" /><SortedDescendingCellStyle BackColor="#FFFDF8" /><SortedDescendingHeaderStyle BackColor="#6F8DAE" /><><asp:TemplateField><HeaderTemplate><asp:CheckBox ID="chkHeader" runat="服务器" OnClick="javascript:SelectAll();" /></HeaderTemplate><ItemTemplate><asp:CheckBox ID="chkDelete" runat="服务器" OnClick="javascript:DeselectHeader();" /></ItemTemplate></asp:TemplateField><asp:TemplateField HeaderText="全名"><ItemTemplate><%#Eval("firstname")+" "+ Eval("姓氏") %></ItemTemplate><EditItemTemplate><asp:TextBox ID="txtFirstName" 宽度="70px" 文本='<%#Eval("firstname")%>' runat="server"></asp:TextBox><asp:TextBox ID="txtLastName" 宽度="70px" 文本='<%#Eval("lastname")%>' runat="server"></asp:TextBox></EditItemTemplate></asp:TemplateField><asp:TemplateField HeaderText="性别"><ItemTemplate><asp:Label ID="lblGender" runat="服务器" 文本='<%#Convert.ToInt32(Eval("性别"))==1?"男":"女"%>'></asp:标签></ItemTemplate><EditItemTemplate><asp:RadioButton ID="rbMale" GroupName="gnGender" runat="服务器" 文本="男" 已选中='<%#eval("gender") %>' /><asp:RadioButton ID="rbFemale" GroupName="gnGender" runat="服务器" 文本="女性"                          已检查='<%#Eval("gender") %>' /></EditItemTemplate></asp:TemplateField><asp:TemplateField HeaderText="Email-Id"><ItemTemplate><%#Eval("email")%></ItemTemplate><EditItemTemplate><asp:TextBox ID="txtEmail" 文本=' <%#Eval("email")%>' runat="服务器"><span>/asp:TextBox></EditItemTemplate></asp:TemplateField><asp:TemplateField HeaderText="用户名"><ItemTemplate><%#Eval("用户名")%></ItemTemplate><EditItemTemplate><asp:TextBox ID="txtUsername" 文本=' <%#Eval("用户名")%>' runat="server" 宽度="65px"></asp:TextBox></EditItemTemplate></asp:TemplateField><asp:TemplateField HeaderText="City"><ItemTemplate><%#Eval("城市名")%></ItemTemplate><EditItemTemplate><asp:DropDownList ID="ddlCity" runat="服务器"><asp:ListItem 文本="选择" ="0" 已选择="True"></asp:ListItem><asp:ListItem 文本="艾哈迈达巴德" ="1"></asp:ListItem><asp:ListItem 文本="Aanand" ="2"></asp:ListItem><asp:ListItem 文本="Bharuch" ="3"></asp:ListItem><asp:ListItem 文本="Valsad" ="4"></asp:ListItem><asp:ListItem 文本="Vadodra" ="5"></asp:ListItem></asp:DropDownList></EditItemTemplate></asp:TemplateField><asp:TemplateField HeaderText="IsActive"><ItemTemplate><asp:LinkBut​​ton OnClick="lnkActive_Click" CommandArgument='<%#Convert.ToInt32(Eval("isactive")) %>'                          ID="lnkActive" runat="服务器" 文本='<%#Eval("isactive").ToString()=="True"?"是":"No"%>'></asp:LinkBut​​ton></ItemTemplate><EditItemTemplate><asp:CheckBox ID="chkIsActive" runat="服务器" 已检查='<%#Eval("isactive") %>' /></EditItemTemplate></asp:TemplateField><asp:CommandField ShowEditButton="true" ShowDeleteButton="true" /></Columns></asp:GridView>


protected void gvAdmin_RowEditing(对象 发件人,GridViewEditEventArgs e){gvAdmin.EditIndex = e.NewEditIndex;填充数据();}protected void gvAdmin_RowCancelingEdit(object sender, GridViewCancelEditEventArgse){gvAdmin.EditIndex = -1;填充数据();}protected void gvAdmin_RowUpdating(object 发件人,GridViewUpdateEventArgse){obj.id = Convert.ToInt64(gvAdmin.DataKeys[e.RowIndex].Value.ToString());文本框 txtFirstName = (TextBox)(gvAdmin.Rows[e.RowIndex].FindControl("txtFirstName"));TextBox txtLastName = (TextBox)(gvAdmin.Rows[e.RowIndex].FindControl("txtLastName"));DropDownList ddlCity = (DropDownList)(gvAdmin.Rows[e.RowIndex].FindControl("ddlCity"));TextBox txtEmail = (TextBox)(gvAdmin.Rows[e.RowIndex].FindControl("txtEmail"));TextBox txtUsername = (TextBox)(gvAdmin.Rows[e.RowIndex].FindControl("txtUsername"));//TextBox txtPassword = (TextBox)(gvAdmin.Rows[e.RowIndex].FindControl("txtPassword"));RadioButton rbMale = (RadioButton)(gvAdmin.Rows[e.RowIndex].FindControl("rbMale"));RadioButton rbFemale = (RadioButton)(gvAdmin.Rows[e.RowIndex].FindControl("rbFemale"));CheckBox chkActive = (CheckBox)(gvAdmin.Rows[e.RowIndex].FindControl("chkIsActive"));obj.flag = "更新";obj.firstname = txtFirstName.Text;obj.lastname = txtLastName.Text;obj.emailid = txtEmail.Text;obj.username = txtUsername.Text;obj.password = "ravi123";obj.isactive = chkActive.Checked;obj.city = Convert.ToInt64(ddlCity.SelectedValue);if (rbMale.Checked == true){obj.gender = Convert.ToBoolean(1);}其他{obj.gender = Convert.ToBoolean(0);}obj.update();gvAdmin.EditIndex = -1;填充数据();}protected void gvAdmin_RowDeleting(object 发件人,GridViewDeleteEventArgse){obj.id = Convert.ToInt64(gvAdmin.DataKeys[e.RowIndex].Value);obj.flag = "删除";obj.Delete();gvAdmin.EditIndex = -1;填充数据();}

推荐答案

看看这些,了解如何实现编辑功能:
在 GridView 中就地编辑[^]
ASP.NET 2.0 中的可编辑 GridView[^]
带有文本框、复选框、单选按钮和下拉列表的可编辑网格视图[^]

试试看!

本文地址:https://www.itbaoku.cn/post/1356200.html