Advertisement

02.05.2008 at 04:44PM PST, ID: 23139971
[x]
Attachment Details

Populate GridView template control (label) when LinkButton clicked

Asked by alanwarren in Programming for ASP.NET, Microsoft Visual Studio Express

ASP .Net 2.0

Scenario:
I have a gridview, paging is enabled, page size 2
In the gridview  <Columns> is a <asp:TemplateField> containing an <ItemTemplate>
In the <ItemTemplate> there are various LinkButton controls wired to VB Subs, each having CommandNames and CommandArguments

The ItemTemplate uses HTML table with a <TFOOT> element  
In the TFOOT I have an asp:Label with an ID of LabelErrorMessage, see code snippet # 1

The problem:
When my LInkButton fires and the associated code is invoked, (see code snipet #2)
I want to populate the associated  Label in the GridViewRow with any message returned by code that is fired when the LinkButton is clicked

Currently my code returns a msgbox  output saying "objGV is Nothing"

I had it working yesterday, but it twas the Label in the first ROW of the GridView Page that was being populated, even if I clicked the LinkButton in the second ROW, hmmm.

Anyhow hope this has not been too long-winded...

Any suggestions?

Alan ";0)Start Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
Snippet # 1
========================================
<ItemTemplate>
  <table>
   <tfoot>
    <tr>
      <td colspan=6 nowrap=nowrap style="color:DarkRed;font-size:small;background-color:#fffff4;border:solid 1px Red; text-align:center;">
        <asp:Label 
        ID = "lblErrorMessage"
        runat = "server"
        EnableViewState = "False"
        Text = "Label"
        Visible = "False"
            >
        </asp:Label>
      </td>
    </tr>
    </tfoot>
  </table>
</ItemTemplate>              
</asp:TemplateField>
========================================
 
Snippet # 2
========================================
    Sub LinkBtn_SVK_Click(ByVal sender As Object, ByVal e As CommandEventArgs)
 
        Dim objLabel As Label = Nothing
        Dim strErrMsg As String = String.Empty
        Dim objGV As GridView = CType(FindControl("GridViewBrowseMemberProfiles"), GridView)
 
 
        If objGV IsNot Nothing Then
            Dim objGVRows As GridViewRowCollection = objGV.Rows
            For Each objRow As GridViewRow In objGVRows
                objLabel = CType(FindControl("lblErrorMessage"), Label)
                If objLabel IsNot Nothing Then
                    strErrMsg = "Hello world"
                    With objLabel
                        .Text = strErrMsg
                        .Visible = True
                    End With
                Else
                    MsgBox("objLabel is Nothing")
                End If
            Next
        Else
            MsgBox("objGV is Nothing")
        End If
 
 
        objLabel = Nothing
 
 
    End Sub
====================================
[+][-]02.05.2008 at 08:05PM PST, ID: 20829402

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]02.06.2008 at 12:00AM PST, ID: 20830270

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: Programming for ASP.NET, Microsoft Visual Studio Express
Sign Up Now!
Solution Provided By: NazoUK
Participating Experts: 1
Solution Grade: A
 
 
[+][-]02.06.2008 at 01:26PM PST, ID: 20835915

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628