gridview中的列表框 [英] Listbox inside gridview
本文介绍了gridview中的列表框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Hai,
我正在使用编辑,删除操作的gridview。在gridview中,几列中的列表框都在< ; edititemtemplate>。如何在listview中使用multiselect选项?然后,如果我更新行意味着列表框中的值没有显示已经选择的值.Plz帮助我。
以下是代码:
< asp:TemplateField HeaderText =ImpactedEntity>
< ItemTemplate>
< asp:Label ID =LblImpactedEntityrunat =serverText ='<%#Eval(ImpactedEntity)%>'>< / asp:Label>
< / ItemTemplate>
< EditItemTemplate>
< asp:ListBox ID =lstImpactedEntityrunat =server>< / asp:ListBox>
< / EditItemTemplate>
< / asp:TemplateField>
< asp:TemplateField HeaderText =ImpactType>
< ItemTemplate>
< asp:Label ID =LblImpactTyperunat =serverText ='<%#Eval(ImpactType)%>'>< / asp:Label>
< / ItemTemplate>
< EditItemTemplate>
< asp:ListBox ID =lstImpactTyperunat =server>
< asp:ListItem Text =ImpactType1Value =ImpactType1>< / asp:ListItem>
< asp:ListItem Text =ImpactType2Value =ImpactType2>< / asp:ListItem>
< asp:ListItem Text =ImpactType3Value =ImpactType3>< / asp:ListItem>
< / asp:ListBox>
< / EditItemTemplate>
< / asp:TemplateField>
解决方案
在.aspx页面:
< pre lang =c#>< asp:gridview id = GridView1 runat = server autogeneratecolumns = False xmlns:asp = #unknown >
< columns>
< asp:templatefield headertext = L1 >
< itemtemplate>
< asp:label id = lbl1 runat = server text = <%#Bind( L1 )%> > < / asp:label > < / itemtemplate >
< / asp:templatefield >
< asp:templatefield headertext = L2 >
<的ItemTemplate>
< asp:label id = lbl2 runat = server text = <%#Bind( L2 )%> > < / asp:label > < / itemtemplate >
< / asp:templatefield >
< asp:templatefield headertext = L3 >
<的ItemTemplate>
< asp:linkbutton id = lbl3 runat = server text = <%#Bind( L3 )%> > < / asp:linkbutton > < / itemtemplate >
< / asp:templatefield >
< asp:templatefield headertext = L3 >
<&的ItemTemplate GT;
< asp:listbox id = lstGrd runat = server selectionmode = 多个 > < / asp:listbox > < / itemtemplate >
< / asp:templatefield >
< / 列 >
< SelectedRowStyle BorderWidth = 2px Font-Bold = True Font-Italic = True />
< / asp:gridview >
和.cs页面:
protected void Page_Load(对象发件人,EventArgs e)
{
DataTable table1 = new DataTable( DTBLE1);
table1.Columns.Add( L1);
table1.Columns.Add( L2);
table1.Columns.Add( L3);
table1.Rows.Add( 1, 5);
table1.Rows.Add( 3, 5);
table1.Rows.Add( 4, 9);
table1.Rows.Add( 7, 3);
table1.Rows.Add( 6, 6);
DataSet Dset = new DataSet( DSET1跨度>);
Dset.Tables.Add(table1);
if (Dset.Tables [ 0 ]。Rows.Count > 0 )
{
for ( int i = 0 ; i < ; Dset.Tables [ 0 ]。Rows.Count; i ++)
{
DataRow dr = Dset.Tables [ 0 跨度>]行[i]中。;
int a = Convert.ToInt32(dr [ L1跨度>]);
int b = Convert.ToInt32(dr [ L2跨度>]);
int c = a + b;
dr [ L3] = c.ToString();
}
}
GridView1.DataSource = Dset;
GridView1.DataBind();
foreach (GridViewRow grdrw GridView1.Rows)
{
ListBox lst =(ListBox)grdrw.FindControl( lstGrd);
ListItem lstitm = new ListItem();
lstitm.Text = Value1;
lstitm.Value = Value1;
lst.Items.Add(lstitm);
lstitm.Text = Value2;
lstitm.Value = Value2;
lst.Items.Add(lstitm);
lstitm.Text = Value3;
lstitm.Value = Value3;
lst.Items.Add(lstitm);
}
}
祝您好运..
Hai,
I am having a gridview with edit,delete operations.In the gridview few columns having listbox in the <edititemtemplate>.How can i use multiselect option in the listview?Then if i am updating the row means the values in listbox is not showing the already selected values.Plz help me.
Below is the code:
<asp:TemplateField HeaderText="ImpactedEntity"> <ItemTemplate> <asp:Label ID="LblImpactedEntity" runat="server" Text='<%# Eval("ImpactedEntity") %>'></asp:Label> </ItemTemplate> <EditItemTemplate> <asp:ListBox ID="lstImpactedEntity" runat="server"></asp:ListBox> </EditItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="ImpactType"> <ItemTemplate> <asp:Label ID="LblImpactType" runat="server" Text='<%# Eval("ImpactType") %>'></asp:Label> </ItemTemplate> <EditItemTemplate> <asp:ListBox ID="lstImpactType" runat="server"> <asp:ListItem Text="ImpactType1" Value="ImpactType1"></asp:ListItem> <asp:ListItem Text="ImpactType2" Value="ImpactType2"></asp:ListItem> <asp:ListItem Text="ImpactType3" Value="ImpactType3"></asp:ListItem> </asp:ListBox> </EditItemTemplate> </asp:TemplateField>
解决方案
In .aspx page:
<asp:gridview id="GridView1" runat="server" autogeneratecolumns="False" xmlns:asp="#unknown"> <columns> <asp:templatefield headertext="L1"> <itemtemplate> <asp:label id="lbl1" runat="server" text="<%# Bind("L1") %>"></asp:label></itemtemplate> </asp:templatefield> <asp:templatefield headertext="L2"> <itemtemplate> <asp:label id="lbl2" runat="server" text="<%# Bind("L2") %>"></asp:label></itemtemplate> </asp:templatefield> <asp:templatefield headertext="L3"> <itemtemplate> <asp:linkbutton id="lbl3" runat="server" text="<%# Bind("L3") %>"></asp:linkbutton></itemtemplate> </asp:templatefield> <asp:templatefield headertext="L3"> <itemtemplate> <asp:listbox id="lstGrd" runat="server" selectionmode="Multiple"></asp:listbox></itemtemplate> </asp:templatefield> </columns> <SelectedRowStyle BorderWidth="2px" Font-Bold="True" Font-Italic="True" /> </asp:gridview>
And in .cs page:
protected void Page_Load(object sender, EventArgs e) { DataTable table1 = new DataTable("DTBLE1"); table1.Columns.Add("L1"); table1.Columns.Add("L2"); table1.Columns.Add("L3"); table1.Rows.Add("1", "5"); table1.Rows.Add("3", "5"); table1.Rows.Add("4", "9"); table1.Rows.Add("7", "3"); table1.Rows.Add("6", "6"); DataSet Dset = new DataSet("DSET1"); Dset.Tables.Add(table1); if (Dset.Tables[0].Rows.Count > 0) { for (int i = 0; i < Dset.Tables[0].Rows.Count; i++) { DataRow dr = Dset.Tables[0].Rows[i]; int a = Convert.ToInt32(dr["L1"]); int b = Convert.ToInt32(dr["L2"]); int c = a + b; dr["L3"] = c.ToString(); } } GridView1.DataSource = Dset; GridView1.DataBind(); foreach(GridViewRow grdrw in GridView1.Rows) { ListBox lst = (ListBox)grdrw.FindControl("lstGrd"); ListItem lstitm = new ListItem(); lstitm.Text = "Value1"; lstitm.Value = "Value1"; lst.Items.Add(lstitm); lstitm.Text = "Value2"; lstitm.Value = "Value2"; lst.Items.Add(lstitm); lstitm.Text = "Value3"; lstitm.Value = "Value3"; lst.Items.Add(lstitm); } }
Best of luck..
这篇关于gridview中的列表框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文