dyarosh
asked on
Is there a way to bind a TextBox to a column in my DataTable in ASP.NET using C#
It seems like I should be able to do this but everything I have found seems to deal with GridView and DetailsView. I have a web page that has fields on it from a datatable. Most of the fields are TextBoxes and DropDownLists. The PageLoad event creates a DataTable and retrieves a single record into the table. Then the data from the record is copied to the TextBoxes and DropDownLists. ASP.NET Validators are used on the TextBoxes and DropDowns and the DropDowns use AJAX calls to populate based on the selected value of a previous DropDown.
All of this is working great. The validation works, the AJAX calls work and now I am ready to save the data. If the TextBoxes and DropDownLists were bound to my DataTable, I would be able to check the RowState to determine if the data has been changed. As part of saving the data, I need to record the fields that were changes showing the old value and new value. Again, if the fields were bound to my datatable I can do this fairly easily.
I just can't figure out how to Bind the fields. I am including a sample of the HTML Markup.
What I need to do is to Bind the following:
txtFirstName TextBox to the FirstName field
txtLastName TextBox to the LastName field
txtNickName TextBox to the NickName field
in my dtEmployee DataTable.
There isn't a DataSource property on the TextBox so I don't know how to tell it to BInd to the dtEmployee Table. Any help would be greatly appreciated!
All of this is working great. The validation works, the AJAX calls work and now I am ready to save the data. If the TextBoxes and DropDownLists were bound to my DataTable, I would be able to check the RowState to determine if the data has been changed. As part of saving the data, I need to record the fields that were changes showing the old value and new value. Again, if the fields were bound to my datatable I can do this fairly easily.
I just can't figure out how to Bind the fields. I am including a sample of the HTML Markup.
<tr>
<td class="requiredField">Legal First Name:</td>
<td><asp:TextBox ID="txtFirstName" runat="server" MaxLength="50" Text=""
Enabled="False" BorderStyle="None" ClientIDMode="Static"></asp:TextBox></td>
<asp:RequiredFieldValidator ID="FirstNameRequiredFieldValidator" runat="server"
ErrorMessage="Please enter Legal First Name"
ControlToValidate="txtFirstName" validationgroup="EmployeeInfo" Display="Dynamic" ToolTip="Please enter Legal First Name">*</asp:RequiredFieldValidator>
<td class="requiredField">Legal Last Name:</td>
<td><asp:TextBox ID="txtLastName" runat="server" MaxLength="50" Text=""
Enabled="False" BorderStyle="None" ClientIDMode="Static"></asp:TextBox></td>
<asp:RequiredFieldValidator ID="LastNameRequiredFieldValidator" validationgroup="EmployeeInfo" runat="server"
ErrorMessage="Please enter Legal Last Name"
ControlToValidate="txtLastName" Display="Dynamic"
ToolTip="Please enter Legal Last Name">*</asp:RequiredFieldValidator>
<td>Nickname:</td>
<td><asp:TextBox ID="txtNickName" runat="server" MaxLength="50" Text=""
BorderStyle="NotSet" ClientIDMode="Static"></asp:TextBox></td>
</tr>
What I need to do is to Bind the following:
txtFirstName TextBox to the FirstName field
txtLastName TextBox to the LastName field
txtNickName TextBox to the NickName field
in my dtEmployee DataTable.
There isn't a DataSource property on the TextBox so I don't know how to tell it to BInd to the dtEmployee Table. Any help would be greatly appreciated!
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER