|
-
Jan 15th, 2006, 12:23 PM
#1
Thread Starter
Frenzied Member
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
-
Jan 16th, 2006, 05:15 AM
#2
Thread Starter
Frenzied Member
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|