How to get bit value from the table and show in checkbox(e.g if value is TRUE then "TICK" show Otherwise checbox "NOT TICK") in "gridview"?How to get checkbox value and insert into database table which have "bit" datatype.Here is my table image image
and here is my gridview image image
Here is my .CS code
public void lbinssert(Object sender,EventArgs e)
{
sql.InsertParameters["ColumnName"].DefaultValue =
((TextBox)GridView1.FooterRow.FindControl("txtColName")).Text;
sql.InsertParameters["Dtype"].DefaultValue =
((DropDownList)GridView1.FooterRow.FindControl("DropDownList2")).Text;
sql.InsertParameters["id"].DefaultValue =
((DropDownList)GridView1.FooterRow.FindControl("DropDownList2")).Text;
sql.InsertParameters["null"].DefaultValue =
((CheckBox)GridView1.FooterRow.FindControl("nulll")).Text;
sql.InsertParameters["primary"].DefaultValue = ((CheckBox)GridView1.FooterRow.FindControl("primary")).Text;
sql.Insert();
}
Here is .aspx code
<asp:TemplateField HeaderText="Column_Name" SortExpression="Column_Name">
<EditItemTemplate>
<asp:TextBox ID="txtName" runat="server" Text='<%#Bind("Column_Name")%>'> </asp:TextBox>
<asp:RequiredFieldValidator Text="*" ID="colname" ControlToValidate="txtName"
runat="server" ErrorMessage="Column Name is Required" ForeColor="Red">
</asp:RequiredFieldValidator>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("Column_Name") %>'></asp:Label>
</ItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtColName" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ValidationGroup="INSERT" Text="*" ID="insertcolname" ControlToValidate="txtColName"
runat="server" ErrorMessage="Column Name is Required" ForeColor="Red">
</asp:RequiredFieldValidator>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Data_Type" SortExpression="Data_Type">
<EditItemTemplate>
<asp:DropDownList ID="DropDownList1" runat="server" SelectedValue='<%# Bind("Data_Type") %>'>
<asp:ListItem>Select Datatype</asp:ListItem>
<asp:ListItem>int</asp:ListItem>
<asp:ListItem>Float</asp:ListItem>
<asp:ListItem>Varchar(50)</asp:ListItem>
<asp:ListItem>Varchar(100)</asp:ListItem>
<asp:ListItem>double</asp:ListItem>
</asp:DropDownList>
<asp:RequiredFieldValidator ID="datatype" ControlToValidate="DropDownList1"
runat="server" ErrorMessage="Data Type is Required" ForeColor="Red" InitialValue="Select Datatype">
</asp:RequiredFieldValidator>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Bind("Data_Type") %>'></asp:Label>
</ItemTemplate>
<FooterTemplate>
<asp:DropDownList ID="DropDownList2" runat="server">
<asp:ListItem>Select Datatype</asp:ListItem>
<asp:ListItem>int</asp:ListItem>
<asp:ListItem>Float</asp:ListItem>
<asp:ListItem>Varchar(50)</asp:ListItem>
<asp:ListItem>Varchar(100)</asp:ListItem>
<asp:ListItem>double</asp:ListItem>
</asp:DropDownList>
<asp:RequiredFieldValidator ValidationGroup="INSERT" Text="*" ID="datatype" ControlToValidate="DropDownList2"
runat="server" ErrorMessage="Data Type is Required" ForeColor="Red" InitialValue="Select Datatype">
</asp:RequiredFieldValidator>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Allow_Null_" SortExpression="Allow_Null_">
<EditItemTemplate>
<asp:CheckBox ID="CheckBox1" runat="server" Checked='<%# DataBinder.Eval(Container.DataItem,"Allow_Null_").ToString().Equals("1") %>'/>
</EditItemTemplate>
<ItemTemplate>
<asp:CheckBox ID="CheckBox1" runat="server" Checked='<%# DataBinder.Eval(Container.DataItem,"Allow_Null_").ToString().Equals("1") %>' enabled="false" />
</ItemTemplate>
<FooterTemplate>
<asp:CheckBox ID="nulll" runat="server" />
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Primary_Key_" SortExpression="Primary_Key_">
<EditItemTemplate>
<asp:CheckBox ID="CheckBox2" runat="server" Checked='<%# DataBinder.Eval(Container.DataItem,"Primary_Key_").ToString().Equals("1") %>' />
</EditItemTemplate>
<ItemTemplate>
<asp:CheckBox ID="CheckBox2" runat="server"
Checked='<%# DataBinder.Eval(Container.DataItem,"Primary_Key_").ToString().Equals("1") %>' Enabled="false" />
</ItemTemplate>
<FooterTemplate>
<asp:CheckBox ID="primary" runat="server" />
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Date" SortExpression="Date">
<EditItemTemplate>
<asp:TextBox ID="TextBox3" runat="server" Text='<%# Bind("Date") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label3" runat="server" Text='<%# Bind("Date") %>'></asp:Label>
</ItemTemplate>
<FooterTemplate>
<asp:LinkButton ValidationGroup="INSERT" OnClick="lbinssert" ID="lblInsert" runat="server">Insert</asp:LinkButton>
</FooterTemplate>
</asp:TemplateField>
<asp:CommandField ShowEditButton="True" />
<asp:CommandField ShowDeleteButton="True" />
</Columns>
<FooterStyle BackColor="#F7DFB5" ForeColor="#8C4510" />
<HeaderStyle BackColor="#A55129" Font-Bold="True" ForeColor="White" />
<PagerStyle ForeColor="#8C4510" HorizontalAlign="Center" />
<RowStyle BackColor="#FFF7E7" ForeColor="#8C4510" />
<SelectedRowStyle BackColor="#738A9C" Font-Bold="True" ForeColor="White" />
<SortedAscendingCellStyle BackColor="#FFF1D4" />
<SortedAscendingHeaderStyle BackColor="#B95C30" />
<SortedDescendingCellStyle BackColor="#F1E5CE" />
<SortedDescendingHeaderStyle BackColor="#93451F" />
</asp:GridView>
<asp:ValidationSummary ValidationGroup="INSERT" ID="ValidationSummary1" ForeColor="Red"
runat="server" Height="54px" style="margin-left: 140px" />
<asp:ValidationSummary ID="ValidationSummary2" ForeColor="Red" runat="server"
style="margin-left: 161px" />
<asp:SqlDataSource ID="sql" runat="server"
ConnectionString="<%$ ConnectionStrings:db_compilerConnectionString %>"
SelectCommand="SELECT [Column_Name], [Data_Type], [Allow_Null_], [Primary_Key_], [Date] FROM [tbl_field]"
DeleteCommand="DELETE * FROM [tbl_field] WHERE [Field_id]=@field" InsertCommand="INSERT INTO [tbl_field] ([Column_Name],[Data_Type],[Database_id],[Allow_Null_],[Primary_Key_])Values (@ColumnName,@Dtype,@id,@null,@primary)"
UpdateCommand="UPDATE [tbl_field] SET [Column_Name]=@ColumnName,[Data_Type]=@Dtype,[Database_id]=@id,[Allow_Null_]=@null,[Primary_Key_]=@primary">
<DeleteParameters>
<asp:Parameter Name="field" Type="Int32" />
</DeleteParameters>
<InsertParameters>
<asp:Parameter Name="ColumnName" Type="String" />
<asp:Parameter Name="Dtype" Type="String" />
<asp:Parameter Name="id" Type="String" />
<asp:Parameter Name="null" Type="Boolean" />
<asp:Parameter Name="primary" Type="Boolean" />
</InsertParameters>
<UpdateParameters>
<asp:Parameter Name="ColumnName" Type="String" />
<asp:Parameter Name="Dtype" Type="String" />
<asp:Parameter Name="id" Type="String" />
<asp:Parameter Name="null" Type="Boolean"/>
<asp:Parameter Name="primary" Type="Boolean" />
</UpdateParameters>
</asp:SqlDataSource>
Value is inserted into the database,but "Allow_Null_" and "Primary_Key_" showing "NULL" ,Please tell me how can i resolve this issue.Thanks
Aucun commentaire:
Enregistrer un commentaire