ASP.NET - how to add extra column in gridview - Asked By shoaib mansoori on 02-Apr-12 05:59 AM

Hi all
i am creating an application,in my page there is button for view customer on click on this view customer is display, for display i have used gridview.
gridview.autogenerated property is true now.
now i want to that if i click on id of the customer it should open a page like address page so how to do?
how can i put html link on customercode click?
or
if it is possible to add one more column which has a link of address page on the click on link according to customercode it will add the address of that particular customer?

thanks
regards
Reena Jain replied to shoaib mansoori on 02-Apr-12 06:27 AM
Hi,

I have added for total, You can also try this

double total=0;
  foreach (GridViewRow rowitem in GridView1.Rows)
  {
  Label PriceLabel =(Label)(rowitem.FindControl("Label1")) as Label;
  TextBox QuantityTxtBx = rowitem.FindControl("TextBox1") as TextBox;
  //double total=0;
   // string total;
  double price = double.Parse(PriceLabel.Text);
  int quantity = int.Parse(QuantityTxtBx.Text);
  total =(price * quantity);
  }
    
  GridView1.FooterRow.Cells[1].Text = total.ToString();
dipa ahuja replied to shoaib mansoori on 02-Apr-12 07:28 AM
Its called master detail concept: Try this code
 
<%--Master GridView--%>
<asp:GridView ID="GridView1" runat="server" DataSourceID="SqlDataSource3" DataKeyNames="empid"
  OnSelectedIndexChanged="GridView1_SelectedIndexChanged">
  <Columns>
    <asp:CommandField ShowSelectButton="True" />
    <asp:BoundField DataField="empid" HeaderText="empid" SortExpression="empid" />
    <asp:BoundField DataField="ename" HeaderText="ename" SortExpression="ename" />
    <asp:BoundField DataField="bdate" HeaderText="bdate" SortExpression="bdate" />
  </Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource3" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
SelectCommand="SELECT * FROM [emp]"></asp:SqlDataSource>
   <%-- Details GridView--%>      
        
<asp:GridView ID="GridView2" runat="server" DataSourceID="SqlDataSource4" AutoGenerateColumns="False">
  <Columns>
    <asp:BoundField DataField="empid" HeaderText="empid" SortExpression="empid" />
    <asp:BoundField DataField="ename" HeaderText="ename" SortExpression="ename" />
    <asp:BoundField DataField="bdate" HeaderText="bdate" SortExpression="bdate" />
  </Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource4" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
SelectCommand="SELECT * FROM [edetail] where empid=@empid">
<SelectParameters>
<asp:ControlParameter ControlID="GridView1" Name="empid" PropertyName="SelectedValue"
Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>