views:

13

answers:

1

Hello All:

I am creating a web application using Asp.net dynamic data. I am using GridView to show data from the database.

In the grid view I am having following code for columns

 <Columns>
                    <asp:DynamicField DataField="UserId"  UIHint="Label" />
                    <asp:DynamicField DataField="Address" UIHint="Address"/>
                    <asp:DynamicField DataField="CreatedDate" UIHint="Label" />
                </Columns>

But, before displaying I want to do some processing in C# code for each row. In normal ASP.net grid view we can handle OnRowDataBound method, and using FindControl("controlid") we can get the control instance, but in case of dynamic data, I am not getting any id attribute for columns, so I am not able to get the control instance to show updated data in that control depending on some conditions.

Thanks, Ashwani

A: 

Try using a TemplateField instead of DynamicField: http://msdn.microsoft.com/en-us/library/bb288032.aspx

An example of how to use:

      <asp:Templatefield headertext="Author Name">
        <Itemtemplate>
          <asp:label id="FirstNameLabel"
            Text= '<%# Eval("au_fname") %>'
            runat="server"/> 
          <asp:label id="LastNameLabel"
            Text= '<%# Eval("au_lname") %>'
            runat="server"/>
        </Itemtemplate>
      </asp:Templatefield>

Here are the options available to you:

            <asp:TemplateField
                AccessibleHeaderText="string"
                ConvertEmptyStringToNull="True|False"
                FooterText="string"
                HeaderImageUrl="uri"
                HeaderText="string"
                InsertVisible="True|False"
                ShowHeader="True|False"
                SortExpression="string"
                Visible="True|False">
                        <ControlStyle />
                        <FooterStyle />
                        <HeaderStyle />
                        <ItemStyle />
                    <AlternatingItemTemplate>
                        <!-- child controls -->
                    </AlternatingItemTemplate>
                    <EditItemTemplate>
                        <!-- child controls -->
                    </EditItemTemplate>
                    <FooterTemplate>
                        <!-- child controls -->
                    </FooterTemplate>
                    <HeaderTemplate>
                        <!-- child controls -->
                    </HeaderTemplate>
                    <InsertItemTemplate>
                        <!-- child controls -->
                    </InsertItemTemplate>
                    <ItemTemplate>
                        <!-- child controls -->
                    </ItemTemplate>
            </asp:TemplateField>
Daniel Dyson