2

i have a datasource, which has an insertparameters, one of which whose type is set to Boolean, but while adding it from code behind insertparameters.defaultvalue always return string.

code behind code:

if (e.CommandName == "InsertNew")
{
    TextBox Title = GridView1.FooterRow.FindControl("txtAddTitle") as TextBox;
    TextBox Quote = GridView1.FooterRow.FindControl("txtAddQuote") as TextBox;
    TextBox QuoteLink = GridView1.FooterRow.FindControl("txtAddQuoteLink") as TextBox;
    CheckBox Published = GridView1.FooterRow.FindControl("chkAddBox") as CheckBox;
    TextBox PublishedDate = GridView1.FooterRow.FindControl("txtAddPublishedDate") as TextBox;

    SqlDataSource1.InsertParameters["Title"].DefaultValue = Title.Text;
    SqlDataSource1.InsertParameters["Quote"].DefaultValue = Quote.Text;
    SqlDataSource1.InsertParameters["QuoteLink"].DefaultValue = QuoteLink.Text;
    SqlDataSource1.InsertParameters["Published"].DefaultValue = Convert.ToString(Published.Checked);
    SqlDataSource1.InsertParameters["PublishedDate"].DefaultValue = PublishedDate.Text;
     SqlDataSource1.Insert();
}

and aspx code for sql datasource is:

<InsertParameters>  
    <asp:Parameter Name="Title" Type="String" />  
    <asp:Parameter Name="Quote" Type="String" />  
    <asp:Parameter Name="QuoteLink" Type="String" />  
    <asp:Parameter Name="Published" Type="Boolean" />  
    <asp:Parameter Name="PublishedDate" Type="DateTime" />  
</InsertParameters>

Please reply how should i set the datatype as boolean from code behind.

1 Answer 1

2

1: Not sure why you are setting DefaultValue instead of the value

Or

2: Can you try this:

SqlDataSource1.InsertParameters["Published"].DefaultValue = Published.Checked==true?"true":"false";
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.