This is a migrated thread and some comments may be shown as answers.

Add 2 columns in Grid, one with textboxes and another with button

1 Answer 72 Views
Grid
This is a migrated thread and some comments may be shown as answers.
kostas
Top achievements
Rank 1
kostas asked on 16 Sep 2012, 04:53 PM
Hello
I have a query and i bind the results with the following code
Dim oConn As OdbcConnection<br>
Dim connectionString As String<br>
connectionString = ConfigurationManager.ConnectionStrings(
"ODBCConnection").ToString<br>
oConn =
New OdbcConnection(connectionString)<br>
commandString =
"SELECT sCode as Κωδικός, sName as Περιγραφή,sUnitOM as ΜΜ,sWhsalePr as Λιανική From smast where sCode like '" + TextBox1.Text + "%' or sSuplCode like '" + TextBox1.Text + "%' order by scode"<br>
Dim myAdapter As New OdbcDataAdapter(commandString, oConn)<br>
Dim productDataSet As DataSet = New DataSet<br>       
myAdapter.Fill(productDataSet)<br>
RadGrid1.DataSource = productDataSet<br>
RadGrid1.DataBind()
I want to add 2 columns, one with textboxes and another with button so the user fills the desired quantity and then press the button to add the product to a shopping cart
Can you help me how to do that?
Thank you

1 Answer, 1 is accepted

Sort by
0
Accepted
Shinu
Top achievements
Rank 2
answered on 17 Sep 2012, 05:36 AM
Hi,

I suppose you need to add a TextBox column and a Button column programmatically. Please try the following code snippet.

C#:
protected void Page_Init(object sender, EventArgs e)
{
    GridTemplateColumn templateColumn = new GridTemplateColumn();
    grid.MasterTableView.Columns.Add(templateColumn);
    templateColumn.ItemTemplate = new MyTemplate();
}
  
public partial class MyTemplate : ITemplate
{
    public void InstantiateIn(Control container)
    {
        TextBox textbox1 = new TextBox();
        textbox1.ID = "TextBox";
        textbox1.Text = "textbox1";
        Button btn = new Button();
        btn.Text = "Text";
        btn.ID = "Button1";
        container.Controls.Add(textbox1);
        container.Controls.Add(btn);
    }
}

Thanks,
Shinu.
Tags
Grid
Asked by
kostas
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Share this question
or