-1

I'm new to .net and jquery.

My gridview shows like this http://s3.postimg.org/erfrxh25f/untitled.jpg

Here is my loginfo click event.

protected void loginfo_click(Object sender, EventArgs e)
{
    Button btn = (Button)(sender);
    Response.Write("<script>");
    Response.Write("window.open('loginfo.aspx?id=" + + "','_blank')");
    Response.Write("</script>");
}

gridview:

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
        DataKeyNames="Book_id" DataSourceID="SqlDataSource1" 
        OnRowCommand="GridView1_RowCommand" 
        EnablePersistedSelection="True" BackColor="White" 
        OnSelectedIndexChanged="GridView1_SelectedIndexChanged" Height="240px" 
        Width="755px" BorderColor="Red" BorderWidth="2px">
        <Columns>
            <asp:BoundField DataField="Book_id" HeaderText="Book_id" InsertVisible="False" 
                ReadOnly="True" SortExpression="Book_id" >
            <ControlStyle BorderColor="Red" />
            </asp:BoundField>
            <asp:BoundField DataField="Book_name" HeaderText="Book_name" SortExpression="Book_name" />
            <asp:BoundField DataField="Author_name" HeaderText="Author_name" SortExpression="Author_name" />
            <asp:BoundField DataField="Publisher_name" HeaderText="Publish_name" SortExpression="Publisher_name" />
            <asp:TemplateField HeaderText="Edit">
               <ItemTemplate>
                 <asp:Button runat="server" ID="btnedit" Text="Edit" CommandName="EditRow"></asp:Button>                    
               </ItemTemplate>
                <ControlStyle BorderColor="#CCFF66" BackColor="#FF0066" ForeColor="White" />
          </asp:TemplateField>
          <asp:TemplateField HeaderText="Delete">
          <ItemTemplate>
                 <asp:Button runat="server" ID="btndelete" Text="Delete" CommandArgument='<%# Eval("Book_id") %>' CommandName="Deleterow"></asp:Button>                    
               </ItemTemplate>
              <ControlStyle BackColor="#FF0066" ForeColor="White" />
          </asp:TemplateField>

          <asp:TemplateField HeaderText="Log Info">
          <ItemTemplate>
                 <asp:Button runat="server" ID="btnloginfo" Text="Log-Info" CommandArgument='<%# Eval("Book_id") %>' Onclick="loginfo_click"/>
               </ItemTemplate>
              <ControlStyle BackColor="#FF0066" ForeColor="White" />
          </asp:TemplateField>
        </Columns>
        <EditRowStyle BorderColor="Red" />
        <HeaderStyle BackColor="#FF0066" BorderColor="#CCFFFF" ForeColor="White" 
            Height="50px" Width="50px" />
        <SelectedRowStyle BackColor="#FF66FF" />
    </asp:GridView>

I just confused how to call bookid in window.open.,

Any help would be highly appreciated.

Thanks,

update:

loginfo.css:

protected void Page_Load(object sender, EventArgs e)
        {
            SqlConnection con = Connection.DBconnection();
            SqlCommand com = new SqlCommand("sp_logdetails", con);
            com.CommandType = CommandType.StoredProcedure;

        }

loginfo.aspx:

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
        DataKeyNames="Book_id" EnablePersistedSelection="True" BackColor="White"  Height="240px" 
        Width="755px" BorderColor="Red" BorderWidth="2px">
        <Columns>
            <asp:BoundField DataField="id" HeaderText="id" InsertVisible="False" 
                ReadOnly="True" SortExpression="Book_id" >
            <ControlStyle BorderColor="Red" />
            </asp:BoundField>
            <asp:BoundField DataField="bookid" HeaderText="bookid" SortExpression="bookid" />
            <asp:BoundField DataField="studentid" HeaderText="studentid" SortExpression="studentid" />
            <asp:BoundField DataField="date" HeaderText="date" SortExpression="date" />
            <asp:BoundField DataField="returndate" HeaderText="returndate" SortExpression="returndate" />
             <asp:BoundField DataField="returnstatus" HeaderText="returnstatus" SortExpression="returnstatus" />

            </Columns>
            </asp:GridView>
pcs
  • 1,864
  • 4
  • 25
  • 49

1 Answers1

0

You are already setting Book_id as a CommandArgument, so you can get the value from there directly by accessing the button through sender object.

protected void loginfo_click(Object sender, EventArgs e)
{
    Button btn = (Button)sender;
    Response.Write("<script>");
    Response.Write("window.open('loginfo.aspx?id=" + btn.CommandArgument + "','_blank')");
    Response.Write("</script>");
}
Bharadwaj
  • 2,535
  • 1
  • 22
  • 35
  • I need to display data in loginfo.aspx page as gridview by callint stored procedure, – pcs Jan 05 '16 at 05:44
  • for that what to do, here is the screenshot http://s21.postimg.org/ri0m4w61z/untitled.jpg – pcs Jan 05 '16 at 05:46
  • what you have till now? I mean how much coding you done so far for that? – Bharadwaj Jan 05 '16 at 05:47
  • I don't know how to call storedprocedure 'sp_logdetails' to display data – pcs Jan 05 '16 at 05:50
  • can you please see my updated post.. i added loginfo and cs code, but this page shows nothing..can you please help? thanks – pcs Jan 05 '16 at 06:07
  • http://stackoverflow.com/questions/12973773/stored-procedure-return-into-dataset-in-c-sharp-net this will show about the execution, and resultant `DataSet` you can assign to `DataSource` of the `GridView`. – Bharadwaj Jan 05 '16 at 06:10
  • in the above link what is TimeRanges? – pcs Jan 05 '16 at 06:13
  • answer is having the sample to execute procedure. Understand the code and use it according to your requirement – Bharadwaj Jan 05 '16 at 06:38