Results 1 to 2 of 2

Thread: C# combo box in ASP.Net datagrid

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Dec 2001
    Posts
    1,331

    C# combo box in ASP.Net datagrid

    Hello

    I want to put a combo box into my datagrid. The combo box will not be filled from the database, but only have number 1 to 50. As this is a quantity that the user can select from and then update the database.

    This is the code l have so far, doesn't really work well. And l am not sure how to fill the combox with the number 1 to 50 using ASP.Net.

    Code:
    <form id="Form1" method="post" runat="server">
    			<asp:DataGrid id="DataGrid1" style="Z-INDEX: 101; LEFT: 360px; POSITION: absolute; TOP: 304px"
    				runat="server" AutoGenerateColumns="False">
    				<Columns>
    					<asp:BoundColumn DataField="ProductCode" HeaderText="Product Code"></asp:BoundColumn>
    					<asp:TemplateColumn HeaderText="Quantity">
    						<ItemTemplate>
    							<asp:DropDownList ID="cboQuantity" runat="server" />
    						</ItemTemplate>
    					</asp:TemplateColumn>
    				</Columns>
    			</asp:DataGrid>
    		</form>
    Many thanks in advance,

    Steve
    steve

  2. #2

    Thread Starter
    Frenzied Member
    Join Date
    Dec 2001
    Posts
    1,331

    Re: C# combo box in ASP.Net datagrid

    Hello,

    Here is the answer.


    private void Page_Load(object sender, System.EventArgs e)
    {
    // Put user code to initialize the page here
    if (!Page.IsPostBack )
    {
    sqlDataAdapter1.Fill(dataSet11);
    DataGrid1.DataSource = dataSet11;
    DataGrid1.DataBind();
    FillCombo();
    }
    }

    Code:

    private void FillCombo()
    {
    int k = 0;
    int j = 1;
    DropDownList cmb ;
    for (k = 0; k < DataGrid1.Items.Count - 1; k++)
    {
    cmb = (DropDownList)DataGrid1.Items[k].FindControl("cboQuantity");
    for (j= 1; j <= 50; j++)
    {
    cmb.Items.Add(j.ToString());
    }
    }
    }

    Just another question. How can l get the value of the combo box item that the user selects. This information needs to be sent to another webform using request.QueryString["quantity"].ToString()

    I am having a big problem with this.

    Thanks for your help.

    Steve
    steve

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width