Pull data values & assign them to a text control
When I click on the dropdown list, ddlTest the ddlTest_SelectedIndexChanged event executes:
CType(Me.GridView1.Rows(Me.GridView1.EditIndex).Fi ndControl("tbxTest"), TextBox).Text = "Newvalue"
The event will update the gridview text box tbxTest with with the value NEWVALUE. I would like to update the tbxTest with a value from the ddlTest data source SqlDataSource1 that matches the ID selected in the ddlTest. The gridview useses a different datasource, but the datasource has a field named test.
How do you modify the Protected Sub ddlTest_SelectedIndexChanged to pull from the SqlDataSource1 instead of inserting the value "NewValue? Please tell me what I am doing wrong?
Existing Code
<asp:TemplateField HeaderText="ID" SortExpression="Id">
<EditItemTemplate>
<asp:DropDownList ID="ddlTest" runat="server" AutoPostBack=true OnSelectedIndexChanged="ddlTest_SelectedIndexChang ed" DataSourceID="SqlDataSource1" DataTextField="Id" DataValueField="Id">
</asp:DropDownList>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="lblFunctions" runat="server" Text='<%# Bind("ID") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Test" SortExpression="Test">
<EditItemTemplate>
<asp:TextBox ID="tbxTest" runat="server" Text='<%# Bind("Test") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="lblTest" runat="server" Text='<%# Bind("Test") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
ddlTest SQLDataSource1:
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:testConnectionString6 %>"
SelectCommand="SELECT tblHR.ID, [tblTest].[Name], [tblTest.[Test] FROM tblHR INNER JOIN [tbTest] ON tblCHR.ID = [tblTest].ID">
</asp:SqlDataSource>
|