开发者

Obtaining value of Textbox contained within DataList: Where did I go wrong?

开发者 https://www.devze.com 2023-03-19 13:04 出处:网络
I\'m attempting to set the parameter of an insert command equal to the value of a text box contained开发者_运维知识库 within a DataList control.@The following is my attempt at finding the relevant con

I'm attempting to set the parameter of an insert command equal to the value of a text box contained开发者_运维知识库 within a DataList control.@ The following is my attempt at finding the relevant control and retrieving its value.

    protected void SqlDataSource1_Inserting(object sender, SqlDataSourceCommandEventArgs e)
{
    TextBox Amt = (TextBox)DataList1.Items[0].FindControl("RadTextBox1"); 
    e.Command.Parameters["@Amount"].Value = Convert.ToDecimal(Amt.Text);
  }

The above code sample does not work but also does not return any syntax errors. I suspect I did something wrong in trying to get the textbox value because the insert statement works fine if I set the @Amount parameter equal to some arbitrary value. Can someone please show me my mistake and how to correct it?

//Additional code per comment

DataList:

<asp:DataList ID="DataList1" runat="server" DataSourceID="SqlDataSource1"><ItemTemplate>

        <telerik:RadTextBox ID="RadTextBox1" runat="server" Text='<%# Eval("TotalProratedAmountDue") %>'>
        </telerik:RadTextBox>
        </ItemTemplate>
    </asp:DataList>

Insert Button:

public void RadButton2_Click(object sender, EventArgs e)
{
    SqlDataSource1.Insert();
}


Perhaps because you're looking for RadTextBox1 but the ID is RadTextBox2?

If Amt.Text returns a NULL, then Convert.ToDecimal(Amt.Text) will return a 0. But I'm not sure what you mean by "the above example does not work". You mean no records get inserted?


Well to start - your code references RadTextBox1 yet in your markup its RadTextBox2

0

精彩评论

暂无评论...
验证码 换一张
取 消