locked
Find and manipulate data in Gridview RRS feed

  • Question

  • User498301973 posted

    Maybe I am wrong with using the Gridview but I know only the way with Classic ASP. I have following problem:

     In a Gridview I make a templatefield like:

     

    1    <asp:TemplateField>
    2      <ItemTemplate>
    3         <div class="UserAvatarContainer">
    4            <asp:Image ID="ImageMemberAvatar" runat="server" CssClass="Avatar" ImageUrl="~/Repository/Bino/Frank.jpg" Width="96" Height="136" />
    5            <asp:Image ID="ImageFrame" runat="server" CssClass="AvatarFrame" ImageUrl="~/library/style/v1/UserAvatar_Mask2.png" Width="102" Height="154" />
    6            <asp:Image ID="ImageOnline" runat="server" CssClass="AvatarOnline" ImageUrl="~/library/style/v1/OnlineSign.gif" Height="9" Width="35" />
    7            <asp:Image ID="ImageFlag" runat="server" CssClass="AvatarFlag" ImageUrl="~/library/app_flags/276.png" Height="11" Width="16" />
    8            <asp:Label ID="LabelMemberCountry" runat="server" CssClass="AvatarCountryCode" Text="DEU"></asp:Label>
    9          </div>
    10      </ItemTemplate>
    11   </asp:TemplateField>
    

     

    The problem is that's tha Data's not in the Database they should be displayed (other table) and I need in Codebehind to Change. To get the Data is not the problem, but how I can display them back?

    In this sample I have the country code '276' and I need to change that to 'DEU'. Also to get in the Gridview (not sure it will possible) the status displayed for a member. If the member is online then display the onlinesign.gif, if not then displayed another image.

    Please if someone have any idea what helps let me know,

    Thank you

    Frank

    Saturday, October 4, 2008 8:57 AM

Answers

  • User848370396 posted

    once the data is binded to gridview, if you wants to make any changes, the best way is to implement gridviewrowdatabound event, here we will write code like below.

    here suppose, i wants to compare label's text, if it is  "376" , i wants to change to "ENU", then i will do like below. 

    if(e.row.rowtype == datacontroltype.datarow)

    {

    Label LabelMemberCountry = (Label)e.Row.FindControl("LabelMemberCountry");

        if(LabelMemberCountry.Text == "376")  

             LabelMemberCountry.Text = "ENU"

     

    )

    }

     also see this link.

    http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.rowdatabound.aspx 

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, October 5, 2008 7:42 AM

All replies

  • User848370396 posted

    once the data is binded to gridview, if you wants to make any changes, the best way is to implement gridviewrowdatabound event, here we will write code like below.

    here suppose, i wants to compare label's text, if it is  "376" , i wants to change to "ENU", then i will do like below. 

    if(e.row.rowtype == datacontroltype.datarow)

    {

    Label LabelMemberCountry = (Label)e.Row.FindControl("LabelMemberCountry");

        if(LabelMemberCountry.Text == "376")  

             LabelMemberCountry.Text = "ENU"

     

    )

    }

     also see this link.

    http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.rowdatabound.aspx 

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, October 5, 2008 7:42 AM
  • User498301973 posted

    Dear ramireddyindia, 

    I try to figure out how this can work. But for now is it not like I was hopeing, because I have to change the File of the Images also and this drives me nuts at the moment.

    But thank you for the reply of my post I will come back to you if it was helpfully.

     Frank

    Monday, October 6, 2008 5:28 AM
  • User848370396 posted

     My intention is to tell you the way, rowdatabound event works only,  But not to give you entire solution.

    Monday, October 6, 2008 5:33 AM
  • User498301973 posted

    Dear ramireddyindia,

    Of course you not make my job and I love a challenge also. Otherwise is it too boring, don't you think. And even if you don't like it but you already gived the solution. Thank you very much.

    The only thing what was confusing is that's you wrote in CSharp and I don't like (but of course everyone can use the language he prefer too) this programm language anyway. The way how it works is:

    Dim LabelArticleHaeder As Label = e.Item.FindControl("LabelArticleHeader")

    Don't wonder, I change the Gridview to Repeater Control. Is much better in my case. But the way is still the same.

    Thank you again,

    Frank

    Monday, October 6, 2008 12:54 PM