Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7946817
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T01:15:24+00:00 2026-06-04T01:15:24+00:00

I have a grid view with template fields and can bind data into it.

  • 0

I have a grid view with template fields and can bind data into it. In my grid view I also have a command field (Select) to print the respective selected row data in a report. when i made the template fields into bound field, the GridView_SelectedIndexChanged() method works properly. But I need the same functionality by keeping the template fields as it is (not changing to Bound Field).

My Grid View is

<asp:GridView ID="dgvGeneralBillList" runat="server" style="font-size:11px;margin:0px auto auto 30px;width:auto;" AutoGenerateColumns="False" CellPadding="4" ForeColor="#333333" OnSelectedIndexChanged="dgvGeneralBillList_SelectedIndexChanged">
            <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
            <Columns>            
                <asp:TemplateField HeaderText="Bill ID">
                    <EditItemTemplate>
                        <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("BillID") %>'></asp:TextBox>
                    </EditItemTemplate>
                    <ItemTemplate>
                        <asp:Label ID="lblBillID" runat="server" Text='<%# Bind("BillID") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Bill No">
                    <EditItemTemplate>
                        <asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("SerialNo") %>'></asp:TextBox>
                    </EditItemTemplate>
                    <ItemTemplate>
                        <asp:Label ID="lblSerialNo" runat="server" Text='<%# Bind("SerialNo") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Billed Week">
                    <EditItemTemplate>
                        <asp:TextBox ID="TextBox3" runat="server" Text='<%# Bind("BilledWeekNo") %>'></asp:TextBox>
                    </EditItemTemplate>
                    <ItemTemplate>
                        <asp:Label ID="lblBilledWeekNo" runat="server" Text='<%# Bind("BilledWeekNo") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Billed Date">
                    <EditItemTemplate>
                        <asp:TextBox ID="TextBox4" runat="server" Text='<%# Bind("BilledWeekDate") %>'></asp:TextBox>
                    </EditItemTemplate>
                    <ItemTemplate>
                        <asp:Label ID="lblBilledWeekDate" runat="server" Text='<%# Bind("BilledWeekDate") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Amount">
                    <EditItemTemplate>
                        <asp:TextBox ID="TextBox5" runat="server" Text='<%# Bind("Amount") %>'></asp:TextBox>
                    </EditItemTemplate>
                    <ItemTemplate>
                        <asp:Label ID="lblAmount" runat="server" Text='<%# Bind("Amount") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Bill Status">
                    <EditItemTemplate>
                        <asp:TextBox ID="TextBox6" runat="server" Text='<%# Bind("BillStatus") %>'></asp:TextBox>
                    </EditItemTemplate>
                    <ItemTemplate>
                        <asp:Label ID="lblBillStatus" runat="server" Text='<%# Bind("BillStatus") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:CommandField SelectText="print" ShowSelectButton="True" />
            </Columns>
            <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
            <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
            <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
            <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
            <EditRowStyle BackColor="#999999" />
            <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
        </asp:GridView>

And the function is

protected void dgvGeneralBillList_SelectedIndexChanged(object sender, EventArgs e)
    {
        clsBill[] oBillList = new clsBill[1];
        clsBill oBill = new clsBill();
        //oBill.BillID = Convert.ToDouble(dgvGeneralBillList.SelectedRow.Cells[0].Text.ToString());
        oBill.BillID = Convert.ToDouble(dgvGeneralBillList.SelectedRow.FindControl("lblBillID").ToString());
        oBillList[0] = oBill;

        if (oBillList.Length < 1)
        {
            lblMessage.Text = "Error : No Bill Entry found";
            return;
        }

        BLBill oBLBill = new BLBill();
        string sErrorMessage = string.Empty;
        Object oOutput = oBLBill.Execute((int)BOCollectionType.ACTION_BILL.ACTION_BILL_GET_SINGLE_REPORT, oBillList, ref sErrorMessage);
        DSBillReport oDSBillReport = new DSBillReport();

        if (sErrorMessage != "")
        {
            lblMessage.Text = sErrorMessage;
            return;
        }
        else
        {
            oDSBillReport = (DSBillReport)oOutput;
            if (oDSBillReport.BillReport.Rows.Count > 0)
            {
                Session["GeneralBill"] = oDSBillReport;
                Session["MedicalBill"] = null;
                Response.Redirect("frmReportHolder.aspx");
            }
        }

        return;
    }

Please help !

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T01:15:25+00:00Added an answer on June 4, 2026 at 1:15 am

    Well, looks like a quite simple solution of this question. Here is the code currently I am using. I just type cast the SelectedRow as GridViewRow and then type cast the required Label in a new Label object (inside the try...catch block). This worked for me so far. Thanks to everyone.

    protected void dgvGeneralBillList_SelectedIndexChanged(object sender, EventArgs e)
        {
            clsBill[] oBillList = new clsBill[1];
            clsBill oBill = new clsBill();
    
            try
            {
                GridViewRow oGridRow = (GridViewRow)dgvGeneralBillList.SelectedRow;
                Label lblID = (Label)oGridRow.FindControl("lblBillID");
                oBill.BillID = Convert.ToDouble(lblID.Text.ToString());
            }
            catch (Exception ex)
            { 
    
            }
    
            oBillList[0] = oBill;
    
            if (oBillList.Length < 1)
            {
                lblMessage.Text = "Error : No Bill Entry found";
                return;
            }
    
            BLBill oBLBill = new BLBill();
            string sErrorMessage = string.Empty;
            Object oOutput = oBLBill.Execute((int)BOCollectionType.ACTION_BILL.ACTION_BILL_GET_SINGLE_REPORT, oBillList, ref sErrorMessage);
            DSBillReport oDSBillReport = new DSBillReport();
    
            if (sErrorMessage != "")
            {
                lblMessage.Text = sErrorMessage;
                return;
            }
            else
            {
                oDSBillReport = (DSBillReport)oOutput;
                if (oDSBillReport.BillReport.Rows.Count > 0)
                {
                    Session["GeneralBill"] = oDSBillReport;
                    Session["MedicalBill"] = null;
                    Response.Redirect("frmReportHolder.aspx");
                }
            }
    
            return;
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a grid view which contains a button in a template field. I
I have a grid view control having some bound and template fields as follows
I have a grid view using bound, hyper link, and template fields. I'm trying
I have a grid view control with Template Field containing Item Template as Checkbox
I have a grid view that is data bound to a dataset. In a
I would like to use a grid view that can expand its rows, also
I have a gridview that displays items details, I added two template fields one
I have a gridview with Template field. I add a checkbox in templatefield .
I have a button inside of a gridview's template field. Onclick i want to
i have this template field inside a gridview. <asp:TemplateField ItemStyle-HorizontalAlign=Center> <ItemTemplate> <asp:ImageButton ID=ImageButton2 ImageUrl=~/images/DeleteRecord.gif

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.