Is there a way to create a label or text in gridview, that overwrites certain cells in a certain row if certain conditions are met?

I’m only in my second month as a professional developer and this is my first time posting, so please forgive any errors!

I’m working with asp.net and I have created a grid view as below. When Status text is set to a particular status I want to cover all of the cells, apart from the status text, in that row with a warning.

The data comes from an MQ string and is managed by a separate class. I’m thinking that a row databound event might be the way to go. I’m thinking something like the code below

Gridview:

 <asp:GridView runat="server" ID="gridDisc"  GridLines="none" AutoGenerateColumns="false" CellPadding="2" HeaderStyle-backColor="#CCEEFF" OnRowDataBound="gridDisc_RowDataBound" >
        &lt;AlternatingRowStyle CssClass="ep1" /&gt;
        &lt;Columns&gt;
            &lt;asp:BoundField DataField="StatusText" /&gt;
            &lt;asp:TemplateField&gt;
                &lt;ItemTemplate&gt;
                    &lt;asp:Label ID="lblPartDesc" runat="server"&gt;&lt;/asp:Label&gt;
                &lt;/ItemTemplate&gt;
            &lt;/asp:TemplateField&gt;
            &lt;asp:BoundField DataField="Qty" /&gt;
            &lt;asp:BoundField DataField="UOI" /&gt;
            &lt;asp:TemplateField&gt;
                &lt;ItemTemplate&gt;
                    &lt;asp:Label ID="lblStockDetails" runat="server"&gt;&lt;/asp:Label&gt;
                &lt;/ItemTemplate&gt;
            &lt;/asp:TemplateField&gt;
            &lt;asp:TemplateField&gt;
                &lt;ItemTemplate&gt;
                    &lt;asp:Label ID="lblDealerInv" runat="server"&gt;&lt;/asp:Label&gt;
                &lt;/ItemTemplate&gt;
            &lt;/asp:TemplateField&gt;
            &lt;asp:BoundField DataField="Listprice" /&gt;
            &lt;asp:BoundField DataField="DiscCode" /&gt;
            &lt;asp:BoundField DataField="OptiInd" /&gt;
            &lt;asp:BoundField DataField="Weight" /&gt;
            &lt;asp:BoundField DataField="ExchangeSurcharge" /&gt;
        &lt;/Columns&gt;
    &lt;/asp:GridView&gt;

Code behind:

protected void gridDisc_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
PartEnquiryLine line = (PartEnquiryLine)e.Row.DataItem;
Label lbl = (Label)e.Row.FindControl(“lblStatusDetails”);
if (line.StatusText == Text[“280”])
{
lbl.Text = Text[“290”]
}

But I haven’t been able to find any guidance on how to create a label that would cover specific cells in that row when triggered. I may be way off with this, but how would I do it?

#c-sharp #asp.net

4 Likes2.40 GEEK