本文介绍了如何在网格视图中插入月份的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何像在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

推荐答案

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


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];
}


这篇关于如何在网格视图中插入月份的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-17 10:45