hi,
I have a table in sql where rights are assigned to a group of users. I have been able to read and display the data correctly into a gridview with checkboxes bound to some of the columns. The code for that is given below.
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
BackColor="LightGoldenrodYellow" BorderColor="Tan" BorderWidth="1px"
CellPadding="2" DataKeyNames="Right_name" Font-Size="10pt"
Font-Names="Arial" GridLines="None" Width="50%"
onselectedindexchanged="GridView1_SelectedIndexChanged" ForeColor="Black"
onrowupdating="GridView1_RowUpdating">
<Columns>
<asp:BoundField DataField="Right_Name" HeaderText="Right" />
<asp:TemplateField HeaderText="Add">
<ItemTemplate>
<asp:CheckBox ID="chkStatus" runat="server" AutoPostBack="true"
Checked='<%# Convert.ToBoolean(Eval("right_add")) %>'
OnCheckedChanged="chkStatus_OnCheckedChanged"
HeaderText="Add"
Text='<%# Eval("right_add").ToString().Equals("True") ? "" : "" %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="View">
<ItemTemplate>
<asp:CheckBox ID="chkView" runat="server" AutoPostBack="true"
Checked='<%# Convert.ToBoolean(Eval("right_view")) %>'
OnCheckedChanged="chkStatus_OnCheckedChanged"
HeaderText="View"
Text='<%# Eval("right_View").ToString().Equals("True") ? "" : "" %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Edit">
<ItemTemplate>
<asp:CheckBox ID="chkEdit" runat="server" AutoPostBack="true"
Checked='<%# Convert.ToBoolean(Eval("right_Edit")) %>'
OnCheckedChanged="chkEdit_OnCheckedChanged"
Text='<%# Eval("right_Edit").ToString().Equals("True") ? "" : "" %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Delete">
<ItemTemplate>
<asp:CheckBox ID="chkDelete" runat="server" AutoPostBack="false"
Checked='<%# Convert.ToBoolean(Eval("right_Delete")) %>'
OnCheckedChanged="chkDelete_OnCheckedChanged"
Text='<%# Eval("right_Delete").ToString().Equals("True") ? "" : "" %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="Right_Value" HeaderText="Value" />
</Columns>
<FooterStyle BackColor="Tan" />
<PagerStyle BackColor="PaleGoldenrod" ForeColor="DarkSlateBlue"
HorizontalAlign="Center" />
<SelectedRowStyle BackColor="DarkSlateBlue" ForeColor="GhostWhite" />
<HeaderStyle BackColor="Tan" Height="20" Font-Bold="True" />
<AlternatingRowStyle BackColor="PaleGoldenrod" />
</asp:GridView>
the c# code for binding the data is as follows
private void LoadData()
{
string constr = @" Server=naheed-pc;Integrated Security=SSPI;Database=lynxcrmdb;";
string query = @"SELECT B.RIGHT_NAME,A.RIGHT_ADD,A.RIGHT_VIEW,A.RIGHT_EDIT,A.RIGHT_DELETE,B.RIGHT_TYPE,A.RIGHT_VALUE FROM USR_ASSIGNED_RIGHTS A,USR_TOTAL_RIGHTS B WHERE A.USR_GRP_ID = '" + cmbGroupName.Text + "' AND A.USR_RIGHT_ID = B.RIGHT_ID UNION SELECT RIGHT_NAME,RIGHT_ADD,RIGHT_VIEW,RIGHT_EDIT,RIGHT_DELETE,RIGHT_TYPE,RIGHT_VALUE FROM USR_TOTAL_RIGHTS WHERE RIGHT_ID NOT IN (SELECT USR_RIGHT_ID FROM USR_ASSIGNED_RIGHTS WHERE USR_GRP_ID = '" + cmbGroupName.Text + "')";
SqlDataAdapter da = new SqlDataAdapter(query, constr);
DataTable table = new DataTable();
da.Fill(table);
GridView1.DataSource = table;
GridView1.DataBind();
}
This code retrieves multiple rows.
A user can check/uncheck the checkboxes at will.
I now want to create an insert string with data from the gridview. How can I do this?