|
在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>
<aspabel ID="Label1" runat="server" Text="表" Visible="False"></aspabel>
<aspropDownList ID="ddltable" runat="server" Width="90px" Visible="False" AutoPostBack="True" OnSelectedIndexChanged="ddltable_SelectedIndexChanged" >
</aspropDownList>
<aspabel ID="Label2" runat="server" Text="Text" Visible="False"></aspabel>
<aspropDownList ID="ddltext" runat="server" Width="90px" Visible="False" >
</aspropDownList>
<aspabel ID="Label3" runat="server" Text="Value" Visible="False"></aspabel>
<aspropDownList ID="ddlvalue" runat="server" Width="90px" Visible="False">
</aspropDownList>
</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又会重新绑定数据之前选好的数据就不见了。
请问该如何处理呢?
|
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
|