Home > ASP.Net > Using DataBinder.Eval in the RowDataBound Event

Using DataBinder.Eval in the RowDataBound Event


Hi

try this example

create a web page and add Gridview on it

<asp:GridView ID="MyGridView"
    runat="server"
    AutoGenerateColumns="False"
    OnRowDataBound="MyGridView_OnRowDataBound">
<Columns>
    <asp:TemplateField HeaderText="License">
    <ItemTemplate>
        <asp: DropDownList ID="ddlMyList" runat="server" />
    </ItemTemplate>
    </asp:TemplateField>
</Columns>
</asp:GridView>

 in code behind :

protected void MyGridView_OnRowDataBound(object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
        DropDownList ddlMyList = (DropDownList)e.Row.FindControl("ddlMyList");

        // Do some logic to populate my ddlMyList with data

        ddlMyList.SelectedValue = DataBinder.Eval(e.Row.DataItem, "ID").ToString();

    }
}

Hope this helps 😀

Good Luck

Advertisements
Categories: ASP.Net
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: