使用下拉列表和复选框填充Gridview [英] Populating Gridview with dropdownlist and checkboxes

查看:162
本文介绍了使用下拉列表和复选框填充Gridview的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



如果有人知道,我的要求很小,请让我知道.

我有一个下拉列表.它包含产品名称列表和用于输入数量的文本框.当我单击添加按钮时,产品名称和数量的详细信息应显示在网格视图中,并且当用户在下拉列表中选择下一个产品时,该文本框应清除,并可以添加新数量;当用户单击添加按钮时,应添加产品详细信息到gridview. Gridview还应该包含以前的详细信息.

Hi,

I have a small requirement if anybody knows please let me know.

I have a dropdown list. It contains the list of product names and text box to enter the quantity. When I click the add button the details of product name and quantity should display in grid-view and when the user select next product in dropdown, the textbox should clear and possibility of adding new quantity and when user click add button the product details should append to gridview. Gridview should contains provious details also.

推荐答案

查看此
Check out this Code Project - Frequently Asked Questions Series 1: The ASP.Net GridView[^]
We have a similar post over there.


javascript
javascript
<table>
           <tr><td><asp:Label ID="lblFmlDate" runat="server" Text="Date"></asp:Label></td>
                <td><asp:TextBox ID="txtFmlDate"  runat="server" Enabled ="False"></asp:TextBox>
                    <asp:ImageButton ID="imgBtnFmlDate" ImageUrl="~/Images/Calendar_scheduleHS.png" runat="server" />
                    <AjaxToolkit:CalendarExtender ID="calExtrFmlDate"

                        OnClientDateSelectionChanged ="checkDate" runat="server"

                        TargetControlID="txtFmlDate" PopupButtonID="imgBtnFmlDate" Enabled="True">
                    </AjaxToolkit:CalendarExtender>
            </td></tr>
            <tr>
            <td><asp:Label ID="lblDisease" runat="server" Text="Disease"></asp:Label></td>
            <td><asp:TextBox ID="txtDisease" Enabled ="False" runat="server" ></asp:TextBox></td>
            <td><asp:Button ID="cmdDiseaseAdd" Enabled ="False" runat="server" Text="Add"

                    width="60px" onclick="cmdDiseaseAdd_Click" ValidationGroup="B"/></td>
            <td><asp:Button ID="cmdDiseaseDel" Enabled ="False" runat="server" Text="Delete"

                    width="60px" onclick="cmdDiseaseDel_Click"/></td>
            </tr><tr>

grid view 
            <td colspan="6">
            <asp:GridView ID="grdFmlHist" runat="server" AllowPaging="True" Enabled ="False"

            AutoGenerateColumns="False" DataKeyNames="Relationship" Height="40px" WIDTH="450px"

            PageSize="8" ShowFooter="True"  onrowdatabound="grdFmlHist_RowDataBound" >
            <PagerSettings Mode="NumericFirstLast" />
            <RowStyle BackColor="WhiteSmoke" BorderColor="CornflowerBlue" ForeColor="Black"

                Height="30px" />
            <Columns>
            <asp:TemplateField HeaderText="S.No">
                  <ItemTemplate>
                      <asp:CheckBox ID="chkSelect" runat="server" />
                </ItemTemplate>
                 </asp:TemplateField>
                 <asp:TemplateField HeaderText="S.No">
                  <ItemTemplate>
                    <%# ((GridViewRow)Container).RowIndex + 1%>
                </ItemTemplate>
                </asp:TemplateField>
                <asp:BoundField DataField="Relationship" HeaderText="Relationship" />
                <asp:BoundField DataField="Disease" HeaderText="Disease" />
                <asp:BoundField DataField="Dates" HeaderText="Dates" />
                <asp:TemplateField>
                <ItemTemplate>
                    <asp:Button ID="btnDisplay" runat="server"  /></ItemTemplate>
                </asp:TemplateField>
              </Columns>
            <FooterStyle BackColor="Silver" Height="25px" />
            <PagerStyle BackColor="DarkGray" />
            <HeaderStyle BackColor="#000084" Font-Bold="True" ForeColor="White" />
        </asp:GridView></td></tr>



单击添加按钮后



After clicking on add button

protected void cmdDiseaseAdd_Click(object sender, EventArgs e)
       {
           List<FmlDiseaseHist> fmlDiseaseList = new List<FmlDiseaseHist>();
           FmlDiseaseHist objFmlDiseaseHist = new FmlDiseaseHist();
           if (chkAddMandatory() == true)
           {
               if (Session["FmlHist"] != null)
               {
                   fmlDiseaseList = (List<FmlDiseaseHist>)(Session["FmlHist"]);
               }

               if (string.IsNullOrEmpty(txtRelation.Text) != true)
               {
                   objFmlDiseaseHist.Relationship = Convert.ToString(txtRelation.Text);
               }
               if (string.IsNullOrEmpty(txtFmlDate.Text) != true)
               {
                   objFmlDiseaseHist.Dates = txtFmlDate.Text;
               }
               if (string.IsNullOrEmpty(txtDisease.Text) != true)
               {
                   objFmlDiseaseHist.Disease = txtDisease.Text;
               }
               txtRelation.Text = "";
               txtFmlDate.Text = dates.Date_Convert(dates.CurDateyyyymmdd());
               txtDisease.Text = "";
               fmlDiseaseList.Add(objFmlDiseaseHist);
               Session["FmlHist"] = fmlDiseaseList;
               grdFmlHist.DataSource = fmlDiseaseList;
               grdFmlHist.DataBind();
           }
       }


这篇关于使用下拉列表和复选框填充Gridview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆