如何在网格视图中插入月份
问题描述:
如何像在Lable中的Jan-march一样在asp.net中的Gridview中插入两个月的名称
假设从一个下拉列表中有两个下拉列表,我选择jan,第二个下拉列表选择march,然后将这两个值插入Gridview一个标签(gridview标签名称为"month"),如jan -march
how to insert two month name in Gridview in asp.net like Jan-march in on Lable
suppose there are two dropdown list from one dropdownlist i select jan and second dropdown list select march, then theses two value insert into Gridview One lable (gridview label name is "month") like jan -march
答
检查此
Hi ,
Check this
protected void Button1_Click(object sender, EventArgs e)
{
List<string> test = new List<string>();
test.Add(DropDownList1.SelectedValue + " , " + DropDownList2.SelectedValue);
GridView1.DataSource = test;
GridView1.DataBind();
((Label)GridView1.Rows[0].Cells[0].FindControl("Label2")).Text = test[0];
}
<div>
<asp:DropDownList ID="DropDownList1" runat="server">
<asp:ListItem>January</asp:ListItem>
<asp:ListItem>February</asp:ListItem>
<asp:ListItem>March</asp:ListItem>
<asp:ListItem>April</asp:ListItem>
</asp:DropDownList>
<asp:DropDownList ID="DropDownList2" runat="server">
<asp:ListItem>January</asp:ListItem>
<asp:ListItem>February</asp:ListItem>
<asp:ListItem>march</asp:ListItem>
<asp:ListItem>april</asp:ListItem>
</asp:DropDownList>
</div>
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:Label ID="Label2" runat="server" ></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
最好的问候
M.Mitwalli
Best Regards
M.Mitwalli
我对此了解甚少,此代码在这里
所以请尝试
I''m know about it little information and this code is here
so please try it
protected void Button1_Click(object sender, EventArgs e)
{
List<string> test = new List<string>();
test.Add(DropDownList1.SelectedValue + " , " + DropDownList2.SelectedValue);
GridView1.DataSource = test;
GridView1.DataBind();
((Label)GridView1.Rows[0].Cells[0].FindControl("Label2")).Text = test[0];
}