Hi,

I have table in Database and i need to get the get the values of column and check for the values. If the value in row of that column is null...the imagebutton in grid view should be disabled.
I am unable to get the rows values.

Can anyone help??

Thanks in Advance.

Dani AI

Generated

: the goal is to disable an ImageButton in a GridView row when a database column is null. 's markup approach (TemplateField + inline Eval/IIf) can work for quick tests, but inline expressions are harder to read and maintain and can be fragile (VB's IIf evaluates both branches). A safer, clearer solution is to handle this in the GridView RowDataBound event in code-behind and explicitly test for DBNull.Value.

Do the DB->DataSet bind as usual (DataAdapter.Fill, set GridView.DataSource, call DataBind). Then in RowDataBound cast the row item to DataRowView, read the column, and set the ImageButton Enabled accordingly. This keeps logic in one place and makes it simple to add trimming, parsing, or other checks.

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowType != DataControlRowType.DataRow) return;

    var drv = (DataRowView)e.Row.DataItem;
    object val = drv["ColumnName"];
    var btn = (ImageButton)e.Row.FindControl("ibtnTestBtn");
    btn.Enabled = (val != DBNull.Value && !string.IsNullOrEmpty(val.ToString()));
}

Troubleshooting tips: confirm the column name exists in the DataSet and the ImageButton ID matches the TemplateField control. Make sure DataBind is called after filling the DataSet (and, if using Page_Load, that binding is wrapped in if (!IsPostBack) when appropriate). For reference, see the GridView RowDataBound model and DataBinder/Eval behavior: GridView.RowDataBound documentation and DataBinder.Eval documentation.

Hello,

Hope this works

<asp:TemplateField>
			<ItemTemplate>
				<asp:ImageButton ID="ibtnTestBtn" ImageUrl="yourimageURI.jpg" Enabled='<%#IIf(IsDBNull(DataBinder.Eval(Container, "DataItem.ColumnName")), True, False)%>' runat="server" />
			</ItemTemplate>
		</asp:TemplateField>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.