FineUI 官方论坛
标题:
grid 模版列内dropdownlist 使用问题询问
[打印本页]
作者:
liko1688
时间:
2013-3-27 13:17
标题:
grid 模版列内dropdownlist 使用问题询问
在grid 模版列内放ID为ddltable的dropdownlist 并绑定ddltable_SelectedIndexChanged 事件
<x:Grid ID="gv_fileds" runat="server" BoxFlex="1" ShowBorder="true" EnableRowNumber="true"
DataKeyNames="name,type,len,COLUMN_KEY,IS_NULLABLE,auto" SortColumnIndex="0"
SortDirection="DESC" Title="表格资料">
<Columns>
<x:BoundField DataField="name" SortField="name" Width="70px" HeaderText="栏位" />
<x:TemplateField Width="120px" HeaderText="标题">
<ItemTemplate>
<asp:TextBox ID="caption" runat="server" Width="110px" Text='<%# Eval("Name") %>'></asp:TextBox>
</ItemTemplate>
</x:TemplateField>
<x:TemplateField Width="420px" HeaderText="控件">
<ItemTemplate>
<asp
abel ID="Label1" runat="server" Text="表" Visible="False"></asp
abel>
<asp
ropDownList ID="ddltable" runat="server" Width="90px" Visible="False" AutoPostBack="True" OnSelectedIndexChanged="ddltable_SelectedIndexChanged" >
</asp
ropDownList>
<asp
abel ID="Label2" runat="server" Text="Text" Visible="False"></asp
abel>
<asp
ropDownList ID="ddltext" runat="server" Width="90px" Visible="False" >
</asp
ropDownList>
<asp
abel ID="Label3" runat="server" Text="Value" Visible="False"></asp
abel>
<asp
ropDownList ID="ddlvalue" runat="server" Width="90px" Visible="False">
</asp
ropDownList>
</ItemTemplate>
</x:TemplateField>
</Columns>
</x:Grid>
protected void ddltable_SelectedIndexChanged(object sender, EventArgs e)
{
for (int i = 0, count = gv_fileds.Rows.Count; i < count; i++)
{
GridRow row = gv_fileds.Rows[i];
System.Web.UI.WebControls.DropDownList ddltable = (System.Web.UI.WebControls.DropDownList)row.FindControl("ddltable");
System.Web.UI.WebControls.DropDownList ddltext = (System.Web.UI.WebControls.DropDownList)row.FindControl("ddltext");
System.Web.UI.WebControls.DropDownList ddlvalue = (System.Web.UI.WebControls.DropDownList)row.FindControl("ddlvalue");
if (ddltable.SelectedItem != null && ddltable.SelectedValue != "")
{
ddltext.DataSource = Utils.GetTable(string.Format(Utils.getflieds, ddltable.SelectedValue, txt_db.Text), txt_server.Text, txt_db.Text, txt_uid.Text, txt_pwd.Text);
ddltext.DataTextField = "name";
ddltext.DataValueField = "name";
ddltext.DataBind();
ddltext.Items.Insert(0, "");
ddlvalue.DataSource = Utils.GetTable(string.Format(Utils.getflieds, ddltable.SelectedValue, txt_db.Text), txt_server.Text, txt_db.Text, txt_uid.Text, txt_pwd.Text);
ddlvalue.DataTextField = "name";
ddlvalue.DataValueField = "name";
ddlvalue.DataBind();
ddlvalue.Items.Insert(0, "");
}
}
// 如果不是重新绑定数据,则需要手工调用UpdateTemplateFields来更新所有TemplateField中的值
gv_fileds.UpdateTemplateFields();
}
但这样写法会有问题
在row1如我已触发ddltable_SelectedIndexChanged,并在ddltext及ddlvalue选取数据。
在row2选取ddltable又会触发一次,row1的ddltext及ddlvalue又会重新绑定数据之前选好的数据就不见了。
请问该如何处理呢?
欢迎光临 FineUI 官方论坛 (https://fineui.com/BBS/)
Powered by Discuz! X3.4