3 Replies - 19301 Views - Last Post: 18 May 2010 - 05:59 PM Rate Topic: -----

#1 surander  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 20-December 09

how to access html div indide gridview

Post icon  Posted 20 December 2009 - 10:54 PM

i have a html div inside my div and a text box on textbox change evend i want to access div tag id how can i get this.
thanks in advance
Is This A Good Question/Topic? 0
  • +

Replies To: how to access html div indide gridview

#2 Jayman  Icon User is offline

  • Student of Life
  • member icon

Reputation: 418
  • View blog
  • Posts: 9,532
  • Joined: 26-December 05

Re: how to access html div indide gridview

Posted 21 December 2009 - 09:07 AM

Are you wanting to access the DIV from the client side or server side?
Was This Post Helpful? 0
  • +
  • -

#3 UnSkiLd  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 21-December 07

Re: how to access html div indide gridview

Posted 18 May 2010 - 08:14 AM

I know this is an old thread but had the same question. I have a GridView that I am trying to add an expandable row too and can't seem to get a reference to the div I created. This is from Server side.

I am creating this dynamically inside the ItemDataBound event:
LinkButton lnkUser = (LinkButton)e.Row.FindControl("lnkUser");

                //only county will be expandable
                if (userType == "2")
                {
                    lnkUser.Click += new EventHandler(lnkUser_Click);


                    #region Create Expandable Row
                    DataGrid newDG = new DataGrid();
                    newDG.AutoGenerateColumns = true;
                    newDG.HeaderStyle.BackColor = System.Drawing.Color.Blue;
                    newDG.HeaderStyle.ForeColor = System.Drawing.Color.White;
                    newDG.HeaderStyle.HorizontalAlign = HorizontalAlign.Center;
                    newDG.ItemStyle.Font.Bold = true;
                    newDG.Width = Unit.Percentage(100.00);
                    DataTable _dt = new DataTable();



                    //create columns                           
                    _dt.Columns.Add("Supervisor Name");
                    _dt.Columns.Add("Supervisor Email");
                    _dt.Columns.Add("Supervisor Phone");



                    //populate grid
                    Label _sn = (Label)e.Row.FindControl("lblSupName");
                    string supname = "";

                    Label _se = (Label)e.Row.FindControl("lblSupEmail");
                    string supemail = "";

                    Label _sp = (Label)e.Row.FindControl("lblSupPhone");
                    string supphone = "";

                    if (null != _sn)
                    {
                        supname = _sn.Text;
                    }

                    if (null != _se)
                    {
                        supemail = _se.Text;
                    }

                    if (null != _sp)
                    {
                        supphone = _sp.Text;
                    }



                    //add new row
                    DataRow dr = _dt.NewRow();
                    dr[0] = supname;
                    dr[1] = supemail;
                    dr[2] = supphone;
                    _dt.Rows.Add(dr);
                    newDG.DataSource = _dt;
                    newDG.DataBind();
                    SetProps(newDG);

                    System.IO.StringWriter sw = new System.IO.StringWriter();
                    System.Web.UI.HtmlTextWriter htw = new System.Web.UI.HtmlTextWriter(sw);
                    newDG.RenderControl(htw);

                    string DivStart = "<DIV id='uniquename" + e.Row.RowIndex.ToString() + "' style='DISPLAY: none;'>";
                    string DivBody = sw.ToString();
                    string DivEnd = "</DIV>";
                    string FullDIV = DivStart + DivBody + DivEnd;

                    int LastCellPosition = e.Row.Cells.Count - 1;
                    int NewCellPosition = e.Row.Cells.Count - 2;

                    e.Row.Cells[0].ID = "CellInfo" + e.Row.RowIndex.ToString();

                    if (e.Row.RowType == DataControlRowType.DataRow)
                    {
                        e.Row.Cells[LastCellPosition].Text = e.Row.Cells[LastCellPosition].Text + "</td><tr><td></td><td colspan='" + NewCellPosition + "'>" + FullDIV;
                    }

                    //lnkUser.Attributes["onclick"] = "HideShowPanel('uniquename" + e.Row.RowIndex.ToString() + "'); ChangePlusMinusText('" + e.Row.Cells[0].ClientID + "'); SetExpandedDIVInfo('" + e.Row.Cells[0].ClientID + "','" + this.txtExpandedDivs.ClientID + "', 'uniquename" + e.Row.RowIndex.ToString() + "');";
                    lnkUser.Attributes["onmouseover"] = "this.style.cursor='pointer'";
                    lnkUser.Attributes["onmouseout"] = "this.style.cursor='pointer'";
                    lnkUser.Attributes["rowid"] = e.Row.RowIndex.ToString();

                    #endregion

                }
                else
                {
                    lnkUser.Click -= new EventHandler(lnkUser_Click);
                    lnkUser.Style["decoration"] = "none";
                }



The onclick event that I am attaching to the lnkbutton works in another site that is using this code. I am modifying it to work with this new app. It calls javascript methods but I want to be able to use the linkbuttons server side event to hide/show the div I am creating.

Uniquename - the name of the div - cannot be found when I do the standard search:
//try to show or hide div
            HtmlGenericControl div = (HtmlGenericControl)GridView2.Rows[curIndex].FindControl("uniquename" + curIndex);

            if (null != div)
            {
                //show or hide
            }





This is my gridview:

<asp:GridView ID="GridView2" runat="server" AllowPaging="False" AllowSorting="False"
                        AutoGenerateColumns="False" DataKeyNames="Id" DataSourceID="SqlDataSource1" OnRowDataBound="GridView2_RowDataBound"
                        onselectedIndexChanged="GridView2_SelectedIndexChanged" OnRowDeleting="GridView2_RowDeleting"
                        CssClass="incomingresults">
                        <Columns>
                            <asp:TemplateField ShowHeader="false">
                                <ItemTemplate>
                                    <ajaxToolkit:ConfirmButtonExtender ID="cbe" runat="server" TargetControlID="lnkbtnDelete"
                                        DisplayModalPopupID="ModalPopupExtender1" />
                                    <ajaxToolkit:ModalPopupExtender ID="ModalPopupExtender1" runat="server" TargetControlID="lnkbtnDelete"
                                        PopupControlID="PNL" OkControlID="ButtonOk" CancelControlID="ButtonCancel" BackgroundCssClass="modalBackground" />
                                    <asp:Panel ID="PNL" runat="server" Style="display: none; width: 300px; background-color: White;
                                        border-width: 2px; border-color: Black; border-style: solid; padding: 20px;">
                                        Are you sure you want to REJECT this user?
                                        <br />
                                        <br />
                                        <div style="margin-left: 20px;">
                                            <label class="label">
                                                Custom Message (Optional)</label>
                                            <asp:TextBox ID="txtCustomMsg" runat="server" TextMode="MultiLine" MaxLength="500"
                                                Rows="5" Columns="30" />
                                        </div>
                                        <br />
                                        <div style="text-align: center;">
                                            <asp:Button ID="ButtonOk" runat="server" Text="Yes" Width="100px" />
                                            <asp:Button ID="ButtonCancel" runat="server" Text="No" Width="100px" />
                                        </div>
                                    </asp:Panel>
                                    <asp:LinkButton ID="lnkbtnDelete" runat="server" CausesValidation="false" CommandName="Delete"
                                        ControlStyle-Font-Underline="true" Text="Reject"></asp:LinkButton>
                                    <asp:LinkButton ID="lnkbtnSelect" runat="server" CausesValidation="false" CommandName="Select"
                                        ControlStyle-Font-Underline="true" Text="Approve"></asp:LinkButton>
                                </ItemTemplate>
                            </asp:TemplateField>
        <%--                    <asp:CommandField ShowSelectButton="True" SelectText="Approve" />--%>
                            <asp:BoundField DataField="Id" HeaderText="Id" Visible="false" InsertVisible="False" ReadOnly="True"
                                SortExpression="Id" />
                            <asp:TemplateField ShowHeader="true" HeaderText="Username">
                                <ItemTemplate>
                                    <asp:LinkButton ID="lnkUser" runat="server" Text='<%#Eval("Username") %>' onclick="lnkUser_Click" />
                                </ItemTemplate>
                            </asp:TemplateField>
                            <%--<asp:BoundField DataField="Username" HeaderText="Username" SortExpression="Username" />--%>
                            <asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" />
                            <%--<asp:BoundField DataField="last_name" HeaderText="Last Name" SortExpression="LastName" />--%>
                            <asp:BoundField DataField="people_soft_id" HeaderText="People Soft" SortExpression="PeopleSoft" />
                            <asp:BoundField DataField="phone_number" HeaderText="Phone" SortExpression="Phone" />
                            <asp:BoundField DataField="email_address" HeaderText="Email" SortExpression="Email" />
                            <asp:TemplateField ShowHeader="true" HeaderText="User Type" Visible="false">
                                <ItemTemplate>
                                    <asp:Label ID="lblUserType" runat="server" />
                                </ItemTemplate>
                            </asp:TemplateField>                    
                            <asp:BoundField DataField="cnty_court_name" HeaderText="County Court Name" SortExpression="CountyCourtName" />
                            <asp:TemplateField ShowHeader="false" Visible="false">
                                <ItemTemplate>
                                    <asp:Label ID="lblSupName" runat="server" Text='<%#Eval("supervisor_name") %>' />
                                    <asp:Label ID="lblSupPhone" runat="server" Text='<%#Eval("Supervisor_Phone") %>' />
                                    <asp:Label ID="lblSupEmail" runat="server" Text='<%#Eval("Supervisor_Email") %>' />
                                </ItemTemplate>
                            </asp:TemplateField>
                            <%-- Now apart of the expandable panel
                            <asp:BoundField DataField="supervisor" HeaderText="Supervisor (Phone)" SortExpression="Supervisor" Visible="false" />
                            <asp:BoundField DataField="supervisor_name" HeaderText="Supervisor Name" SortExpression="SupervisorName" />
                            <asp:BoundField DataField="supervisor_email" HeaderText="Supervisor Email" SortExpression="SupervisorEmail" Visible="false" />
                            --%>
                            
                            <asp:TemplateField ShowHeader="true" HeaderText="User Role" Visible="false">
                                <ItemTemplate>
                                    <asp:Label ID="lblroleId" runat="server" />
                                </ItemTemplate>
                            </asp:TemplateField>
                          
                        </Columns>               
                        <RowStyle CssClass="incomingresults" />
                        <HeaderStyle CssClass="incomingresults" ForeColor="White" />
                    </asp:GridView>



Ok not sure what else to post so I'll leave it like this. Hope it made sense, if not ask and I'll try to explain. Thanks for the help.
Was This Post Helpful? 0
  • +
  • -

#4 Jayman  Icon User is offline

  • Student of Life
  • member icon

Reputation: 418
  • View blog
  • Posts: 9,532
  • Joined: 26-December 05

Re: how to access html div indide gridview

Posted 18 May 2010 - 05:59 PM

In order to be able to access any control from the server side, it needs to include the 'runat' tag.

Quote

HTML elements in ASP.NET files are, by default, treated as text. To make these elements programmable, add a runat="server" attribute to the HTML element.


http://www.w3schools...et_controls.asp

Modify this code to the following:
string DivStart = "<DIV id='uniquename" + e.Row.RowIndex.ToString() + "' runat='server' style='DISPLAY: none;'>";

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1