This is a migrated thread and some comments may be shown as answers.

how to find column values of a selected row in a radgrid....

4 Answers 1736 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Babu Puchakayala
Top achievements
Rank 1
Babu Puchakayala asked on 29 Jul 2010, 04:29 PM
Hi,

I am using radgrid with rowcontextmenu. when i right click on a radgrid row and select edit option it will open a popup window. What i need is when i rightclick on a radgrid row, i just want to get the values of 3 columns for that particular selected row.  For example, when i right click on a selected radgrid row i want to get customer name, headend name, site name values of that selected row.

Here is my code....


<MasterTableView GridLines="None" DataKeyNames="orderId" CommandItemDisplay="Top">
                            <Columns>
                                <telerik:GridClientSelectColumn UniqueName="ClientSelectColumn" HeaderStyle-Width="3%"
                                    ItemStyle-Width="3%">
                                    <HeaderStyle Width="3%"></HeaderStyle>
                                    <ItemStyle Width="3%"></ItemStyle>
                                </telerik:GridClientSelectColumn>
                                <telerik:GridBoundColumn UniqueName="sId" HeaderText="sId" DataField="sId" ReadOnly="true"
                                    Visible="false">
                                </telerik:GridBoundColumn>
                                <telerik:GridBoundColumn UniqueName="orderId" HeaderText="orderId" Visible="false"
                                    ReadOnly="true" DataField="orderId">
                                </telerik:GridBoundColumn>
                                <telerik:GridBoundColumn UniqueName="Customer Name" HeaderText="Customer Name" DataField="Customer Name"
                                    ReadOnly="true">
                                </telerik:GridBoundColumn>
                                <telerik:GridBoundColumn UniqueName="Market Name" HeaderText="Market Name" DataField="Market Name"
                                    ReadOnly="true">
                                </telerik:GridBoundColumn>
                                <telerik:GridBoundColumn UniqueName="LOB" HeaderText="LOB" DataField="LOB" ReadOnly="true">
                                </telerik:GridBoundColumn>
                                <telerik:GridBoundColumn UniqueName="Headend Name" HeaderText="Headend Name" DataField="Headend Name"
                                    ReadOnly="true">
                                </telerik:GridBoundColumn>
                                <telerik:GridBoundColumn UniqueName="Project Name" HeaderText="Project Name" DataField="Project Name"
                                    ReadOnly="true">
                                </telerik:GridBoundColumn>
                                <telerik:GridTemplateColumn UniqueName="Site Name" HeaderText="Site Name" DataField="SiteName"
                                    ReadOnly="true">
                                    <ItemTemplate>
                                        <asp:LinkButton ID="lnkSiteName" runat="server" Text='<%# Eval( "Site Name" ) %>'
                                            ForeColor="Blue" CommandName="sitename"></asp:LinkButton>
                                    </ItemTemplate>
                                </telerik:GridTemplateColumn>
                                <telerik:GridBoundColumn UniqueName="Task Status" HeaderText="Task Status" DataField="Task Status"
                                    ReadOnly="true">
                                </telerik:GridBoundColumn>
                                <telerik:GridBoundColumn UniqueName="Clarify Account Nbr" HeaderText="Clarify Account Nbr"
                                    DataField="Clarify Account Nbr">
                                </telerik:GridBoundColumn>
                                <telerik:GridBoundColumn UniqueName="Site ID" HeaderText="Site ID" DataField="Site ID">
                                </telerik:GridBoundColumn>
                                <telerik:GridBoundColumn UniqueName="Quote ID" HeaderText="Quote ID" DataField="Quote ID">
                                </telerik:GridBoundColumn>
                                <telerik:GridCheckBoxColumn UniqueName="EDP Created?" HeaderText="EDP Created?" DataField="EDP Created?">
                                </telerik:GridCheckBoxColumn>
                                <telerik:GridEditCommandColumn UniqueName="EditCommandColumn" Display="false">
                                </telerik:GridEditCommandColumn>
                            </Columns>
                        </MasterTableView>


protected void RadMenu1_ItemClick(object sender, RadMenuEventArgs e)
    {
        int radGridClickedRowIndex;
 
        radGridClickedRowIndex = Convert.ToInt32(Request.Form["radGridClickedRowIndex"]);
 
        switch (e.Item.Text)
        {
            case "Edit Task":
                string OrdID = rg200.MasterTableView.DataKeyValues[radGridClickedRowIndex]["orderId"].ToString();
                lblOrdHeadName.Text = rg200.MasterTableView.NamingContainer.FindControl("Headend Name").ToString();
 
                Session["orderId"] = OrdID;
        }
    }


if you see the above code, I am able to get the orderId value for that selected column. But when I am trying to get Headend Name value I am getting error. How to get headend Name value for selected row.

Thanks In Advance

4 Answers, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 2
answered on 30 Jul 2010, 07:09 AM
Hello Babu,

Try the following code snippet to achieve this.

C#:
case "Edit Task":
   {
      string OrdID = RadGrid1.MasterTableView.DataKeyValues[radGridClickedRowIndex]["orderId"].ToString();
      GridDataItem item = (GridDataItem)rg200.MasterTableView.Items[radGridClickedRowIndex];
      lblOrdHeadName.Text = item["HeadendName"].Text;
   }
 
Thanks,
Princy.
0
Babu Puchakayala
Top achievements
Rank 1
answered on 30 Jul 2010, 02:54 PM
Hi Princy,

Thank you so much. Its working great. Thanks Once again.
0
Babu Puchakayala
Top achievements
Rank 1
answered on 31 Jul 2010, 05:30 PM
HI princy,

I have one more question, I Implemented popup window with radtabs option in it. I have textboxe and dropdownlist in second tab.  (see diagram 1 below) When I am trying to find control of that textbox i am getting error like "Object reference not set to an instance of an object." Here is my  code. Can you help me how to solve this issue. Thanks.

here is my code

<telerik:RadWindow ID="WinEditForm" runat="server" ShowContentDuringLoad="false"
                            Width="650px" Height="400px" Title="Action" Behaviors="Default" Animation="FlyIn">
                            <ContentTemplate>
                                <div style="padding-top: 15px; padding-left: 10px">
                                    <asp:UpdatePanel runat="server" ID="UpEditForm" OnUnload="RegisterUpdatePanel4">
                                        <ContentTemplate>
                                            <div style="padding-right: 20px; padding-top: 15px; text-align: center">
                                                <table class="customFont" cellspacing="5" width="100%">
<tr>
                                                                    <td>
                                                                        <telerik:RadTabStrip runat="server" ID="RadTabStrip1" Orientation="HorizontalTop"
                                                                            SelectedIndex="0" MultiPageID="RadMultiPage1" Align="Left">
                                                                            <Tabs>
                                                                                <telerik:RadTab Text="Task Data" PageViewID="RadPageView1">
                                                                                </telerik:RadTab>
                                                                                <telerik:RadTab Text="Notes" PageViewID="RadPageView2">
                                                                                </telerik:RadTab>
                                                                            </Tabs>
                                                                        </telerik:RadTabStrip>
                                                                        <telerik:RadMultiPage runat="server" ID="RadMultiPage1" SelectedIndex="0">
                                                                            <telerik:RadPageView runat="server" ID="RadPageView1">
                                                                                <table id="Table3" cellspacing="1" cellpadding="1" width="350" border="0">
                                                                                    <tr>
                                                                                        <td>
                                                                                        </td>
                                                                                        <td>
                                                                                        </td>
                                                                                    </tr>
                                                                                    <br />
                                                                                    <tr>
                                                                                        <td>
                                                                                            Clarify Account Nbr:
                                                                                        </td>
                                                                                        <td align="left">
                                                                                            <asp:TextBox ID="TextBox1" runat="server">
                                                                                            </asp:TextBox>
                                                                                        </td>
                                                                                    </tr>
                                                                                    <tr>
                                                                                        <td>
                                                                                            Site ID:
                                                                                        </td>
                                                                                        <td align="left">
                                                                                            <asp:TextBox ID="TextBox2" runat="server" TabIndex="1">
                                                                                            </asp:TextBox>
                                                                                        </td>
                                                                                    </tr>
                                                                                    <tr>
                                                                                        <td>
                                                                                            Quote ID:
                                                                                        </td>
                                                                                        <td align="left">
                                                                                            <asp:TextBox ID="TextBox3" runat="server" TabIndex="2">
                                                                                            </asp:TextBox>
                                                                                        </td>
                                                                                    </tr>
                                                                                    <tr>
                                                                                        <td>
                                                                                            EDP Created?:
                                                                                        </td>
                                                                                        <td align="left">
                                                                                            <asp:CheckBox ID="CheckBox1" runat="server" TabIndex="3"></asp:CheckBox>
                                                                                        </td>
                                                                                    </tr>
                                                                                    <tr>
                                                                                        <td align="right" colspan="2">
                                                                                            <asp:Button ID="btnUpdate" runat="server" Text="Update" OnClick="btnUpdate_Click">
                                                                                            </asp:Button
                                                                                            <asp:Button ID="btnCancel" Text="Cancel" runat="server" CausesValidation="False"
                                                                                                CommandName="Cancel"></asp:Button>
                                                                                        </td>
                                                                                    </tr>
                                                                                </table>
                                                                            </telerik:RadPageView>
                                                                            <telerik:RadPageView runat="server" ID="RadPageView2">
                                                                                <table id="Table2" cellspacing="1" cellpadding="1" width="350" border="0">
                                                                                    <tr>
                                                                                        <td>
                                                                                            <br />
                                                                                            <table id="Tablenotes">
                                                                                                <tr>
                                                                                                    <td align="left">
                                                                                                        Note Type :
                                                                                                        <asp:DropDownList ID="DropDownList1" runat="server">
                                                                                                        </asp:DropDownList>
                                                                                                    </td>
                                                                                                    <td align="left">
                                                                                                    </td>
                                                                                                </tr>
                                                                                                <tr>
                                                                                                    <td align="left" colspan="2">
                                                                                                        Note Description
                                                                                                    </td>
                                                                                                </tr>
                                                                                                <tr>
                                                                                                    <td align="left">
                                                                                                        <asp:TextBox ID="TextBox4" runat="server" TextMode="MultiLine" Rows="2" Width="300px"></asp:TextBox>
                                                                                                    </td>
                                                                                                    <td>
                                                                                                           
                                                                                                        <asp:ImageButton ID="ImageButton3" OnClick="btnAddNote_Click" runat="server" ToolTip="Add Note"
                                                                                                            ImageUrl="~/Images/add-icon.png" />
                                                                                                        <asp:ImageButton Visible="false" ToolTip="Update" OnClick="imgbtnNotesUpdate_Click"
                                                                                                            ID="imgbtnNotesUpdate" runat="server" ImageUrl="~/Images/accept-icon.png" />
                                                                                                        <asp:ImageButton Visible="false" ToolTip="Cancel" OnClick="imgbtnNotesCancel_Click"
                                                                                                            ID="imgbtnNotesCancel" runat="server" ImageUrl="~/Images/delete-icon.png" />
                                                                                                    </td>
                                                                                                </tr>
                                                                                                <tr>
                                                                                                    <td>
                                                                                                    </td>
                                                                                                </tr>
                                                                                            </table>
                                                                                        </td>
                                                                                    </tr>
                                                                                    <tr>
                                                                                        <td>
                                                                                        </td>
                                                                                    </tr>
                                                                                    <tr>
                                                                                        <td>
                                                                                            <div style="overflow: auto; height: 160px">
                                                                                                <asp:GridView ID="gvNotes" BorderColor="#004000" runat="server" AutoGenerateColumns="false"
                                                                                                    BackColor="White" BorderWidth="1px" BorderStyle="Solid" CellSpacing="0" Width="100%"
                                                                                                    OnSelectedIndexChanged="gvNotes_SelectedIndexChanged" OnRowDataBound="gvNotes_RowDataBound">
                                                                                                    <HeaderStyle Height="20px" BackColor="#004000" Font-Size="8pt" Font-Bold="True" ForeColor="White"
                                                                                                        HorizontalAlign="Center" BorderColor="White" BorderWidth="0px" />
                                                                                                    <PagerSettings Mode="NumericFirstLast"></PagerSettings>
                                                                                                    <RowStyle ForeColor="#000000" Font-Size="8pt" HorizontalAlign="Left" BorderWidth="1px"
                                                                                                        BorderColor="#004000" />
                                                                                                    <AlternatingRowStyle Font-Size="8pt" ForeColor="#000000" BackColor="#F5F5E9" BorderWidth="1px"
                                                                                                        BorderColor="#004000" />
                                                                                                    <PagerStyle HorizontalAlign="Right" Font-Bold="true" Font-Size="8pt" />
                                                                                                    <Columns>
                                                                                                        <asp:TemplateField Visible="false">
                                                                                                            <ItemTemplate>
                                                                                                                <asp:Label ID="lblonID" runat="server" Text='<%# Bind("onID") %>'></asp:Label>
                                                                                                            </ItemTemplate>
                                                                                                            <ItemStyle HorizontalAlign="Left" />
                                                                                                        </asp:TemplateField>
                                                                                                        <asp:BoundField HeaderText="Note Description" DataField="Description" />
                                                                                                        <asp:BoundField HeaderText="Note Type" DataField="Type" />
                                                                                                        <asp:BoundField HeaderText="Created By" DataField="CreatedBy" />
                                                                                                        <asp:BoundField DataFormatString="{0:MM/dd/yyyy}" HeaderText="Created Date" DataField="CreationDate" />
                                                                                                    </Columns>
                                                                                                </asp:GridView>
                                                                                            </div>
                                                                                        </td>
                                                                                    </tr>
                                                                                </table>
                                                                            </telerik:RadPageView>
                                                                        </telerik:RadMultiPage>
                                                                    </td>
                                                                </tr>
</ContentTemplate>
                                    </asp:UpdatePanel>
                                </div>
                            </ContentTemplate>
                        </telerik:RadWindow>


protected void btnAddNote_Click(object sender, EventArgs e)
    {
 
        clsTaskUpdates_BL objBL = new clsTaskUpdates_BL();
        string strName = Session["UserName"].ToString();
 
        string OrdID = (string)Session["orderId"];
        RadPageView PageView = (RadPageView)WinEditForm.ContentContainer.FindControl("RadPageView2");
        TextBox NoteTxt = (TextBox)PageView.FindControl("txtNoteDesc");
        string NoteDesc = NoteTxt.Text;
        DropDownList DDL = (DropDownList)PageView.FindControl("ddlNoteType");
        string NoteType = DDL.Text;
}

I also tried another way but no luck

string OrdID = (string)Session["orderId"];
        string NoteType = (WinEditForm.ContentContainer.FindControl("RadPageView2").FindControl("ddlNoteType") as DropDownList).Text;
        string NoteDesc = (WinEditForm.ContentContainer.FindControl("RadPageView2").FindControl("txtNoteDesc") as TextBox).Text;


Please let me know how to find the answer




0
Accepted
Princy
Top achievements
Rank 2
answered on 02 Aug 2010, 07:46 AM
Hello Babu,

Try the following code snippet to access the TextBox inside RadPageView.

C#:
protected void btnAddNote_Click(object sender, ImageClickEventArgs e)
   {
     ImageButton btn = (ImageButton)sender;
     RadPageView pageView2 = (RadPageView)btn.Parent;    //accessing RadPageView
     TextBox NoteTxt = (TextBox)pageView2.FindControl("TextBox4");   //accessing TextBox
   }

Thanks,
Princy.
Tags
Grid
Asked by
Babu Puchakayala
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Babu Puchakayala
Top achievements
Rank 1
Share this question
or