我有一个数据源,它有一个插入参数,其中一个类型设置为布尔值,但是从insertparameters.defaultvalue后面的代码添加它时总是返回字符串。
代码背后的代码:
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();
}
和sql datasource的aspx代码是:
<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>
请回复我应该如何从后面的代码中将数据类型设置为boolean。
答案 0 :(得分:2)
1:不确定为什么要设置DefaultValue而不是值
或者
2:你能试试这个:
SqlDataSource1.InsertParameters["Published"].DefaultValue = Published.Checked==true?"true":"false";