Question: How can I change the value of a textbox whenever a dropdownlist within a gridview has its value changed?

On page load, the textbox shows the selected value, but when I change the selection of the dropdownlist, the textbox value doesn't change.

The code is below.

```
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns = "false">
    <Columns>
        <asp:TemplateField HeaderText="Entry">
            <ItemTemplate>
                <%# Container.DataItemIndex + 1 %>
            </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField HeaderText="Duty">
            <ItemTemplate>
                <asp:DropDownList ID="duty" runat="server" OnLoad = "ddl1_load" OnSelectedIndexChanged="duty_SelectedIndexChanged" autopostback="true" EnableViewState="true"></asp:DropDownList>
            </ItemTemplate>
        </asp:TemplateField>
    </Columns>
</asp:GridView>

```

The code behind is below.

```
protected void ddl1_load(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
        DataTable dt = new DataTable();
        Duty dy = new Duty();
        dt = dy.getdutyid(Convert.ToInt32(dropcontractid.SelectedValue));
        DropDownList ddl = (DropDownList)sender;
        ddl.DataSource = dt;
        ddl.DataTextField = "dutyid";
        ddl.DataValueField = "dutyid";
        ddl.DataBind();
        TextBox1.Text = ddl.SelectedValue;
    }
}

```

Answer: 
I had a similar problem using the `DropDownLists` in `GridView`. My solution was to adjust the `onLoad` for the dropdown so that it wouldn't re-write the `DropDownList` on every post back. This way if there's something there then it won't re-populate it.

```
protected void dropDownLoad(object sender, EventArgs e)
{
    DropDownList dropDown = sender as DropDownList;
    if (dropDown.SelectedValue == null || dropDown.SelectedValue == "")
    { 
        // Your Code to populate table
    }
}

```
You should look into using data binding instead. You can bind the textbox.Text to the selecteditem.value, this will ensure that proper updating takes place