I have datagridview in my program I have to create table at run time and also give primary and foreign key at run time.
please tell me methods to do this.I have taken four cell(variable name(textbox),data type(combobox),primary key(checkbox),foreign key(checkbox)).When click check box of foreign key display message("select").
How to perform this.
Loading
Amit ChoudharyPosted Mar 20, 2010, 7:18 AM
In your grid view add template column and add the CheckBox control from toolbox.
Bind the grid.
set the grid properties like this:
Now add the code for GridView1_RowDataBound event like below:
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
CheckBox c = (CheckBox)e.Row.FindControl("CheckBox1");
Label l = (Label)e.Row.FindControl("Label1");
c.Attributes["onClick"] = "if(" + c.ClientID + ".checked==true){alert('you have selected " + l.Text + "')}";
}
}
Download the attach project. Change the connection string and change the other template fields and enjoy the coding.
Please mark as answer if it helps you.