<asp:TemplateField HeaderText="父节点">
<EditItemTemplate>
<asp:DropDownList ID="DropDownList1" runat="server"
DataSourceID="SqlDataSource_ZipNode" DataTextField="DistrictDesc"
DataValueField="DistrictId" SelectedValue='<%# Bind("ParentId") %>'
AppendDataBoundItems="True" ondatabinding="DropDownList1_DataBinding"
ondatabound="DropDownList1_DataBound"
onselectedindexchanged="DropDownList1_SelectedIndexChanged">
<asp:ListItem Enabled="false"></asp:ListItem>
</asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSource_ZipNode" runat="server"
ConnectionString="<%$ ConnectionStrings:connStr %>"
SelectCommand="prd_SelectDistrictNodes" SelectCommandType="StoredProcedure">
</asp:SqlDataSource>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label3" runat="server" Text='<%# Bind("ParentId") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
要点已经标出
//上面这种方法有局限性,还有一种通用的方法
<EditItemTemplate> 模版里的DropDownList 不用SelectedValue绑定
在GridView事件 _RowUpdating
DropDownList objtemp_ZipId=GV_SheBeiDelete.Rows[e.RowIndex].FindControl("DropDownList3") as DropDownList;
DropDownList objtemp_DvsTypeId = GV_SheBeiDelete.Rows[e.RowIndex].FindControl("DropDownList4") as DropDownList;
e.NewValues["ZipId"] = objtemp_ZipId.Text;
e.NewValues["DvsTypeId"] = objtemp_DvsTypeId.Text;
当然对于编辑模版里的 DropDownList 要写事件 DropDownList4_DataBound
DropDownList obj = sender as DropDownList;
try
{
obj.Text = DvsTypeId_GV_SheBeiDelete; ; //变量,其取值在GridView的RowEditing事件里
}
catch
{
}
本文作者:网友 来源:网络
CIO之家 www.ciozj.com 微信公众号:imciow
免责声明:本站转载此文章旨在分享信息,不代表对其内容的完全认同。文章来源已尽可能注明,若涉及版权问题,请及时与我们联系,我们将积极配合处理。同时,我们无法对文章内容的真实性、准确性及完整性进行完全保证,对于因文章内容而产生的任何后果,本账号不承担法律责任。转载仅出于传播目的,读者应自行对内容进行核实与判断。请谨慎参考文章信息,一切责任由读者自行承担。