Click here to Skip to main content
15,884,176 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
I have a grid view like this
create, Edit,Print, ID, Name, HBL_NO, AMount
here i want to get the selected row value of HBL_NO
here create , Edit and print are image button and item template field,
when i click create button i want the HBL_NO to the corresponding row
i have tried like this , but i m getting error in that
C#
string s = gvBSV.SelectedRow.Cells[4].Text;
 Response.Redirect("Delivery_Order.aspx?BL_Code=" + ((ImageButton)sender).CommandName + "&Purpose=N&Menu_ID=" + hndMenu_ID.Value +"&HBL_NO="+s.ToString());

here the s contain the HBL_NO
but i m getting error
ie,.

Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Source Error:

<br />
Line 422:    {<br />
Line 423:        //Response.Redirect("Delivery_Order.aspx?BL_Code=" + ((ImageButton)sender).CommandName + "&Purpose=N&Menu_ID=" + hndMenu_ID.Value + "&BL_Type=" + ViewState["BL_Type"].ToString());<br />
Line 424:        string s = gvBSV.SelectedRow.Cells[4].Text;<br />
Line 425:        //Session["HBL"] = gvBSV.SelectedRow.Cells[4].Text;       <br />
Line 426:        Response.Redirect("Delivery_Order.aspx?BL_Code=" + ((ImageButton)sender).CommandName + "&Purpose=N&Menu_ID=" + hndMenu_ID.Value +"&HBL_NO=");
Posted
Updated 28-Nov-11 23:04pm
v2

try this..

on row cammand event..

C#
Protected void gvBSV_RowCommand(Object sender, GridViewCommandEventArgs e)
{
    GridViewRow gdvrow = (GridViewRow)((e.CommandSource).Parent.Parent);
    string s = gdvrow.cells["HBL_NO"].Text;
 
    Response.Redirect("Delivery_Order.aspx?BL_Code=" + e.CommandName + "&Purpose=N&Menu_ID=" + hndMenu_ID.Value +"&HBL_NO="+s.ToString());
}


hope this helps..
 
Share this answer
 
Comments
rajrprk 29-Nov-11 6:21am    
here i m getting error 'object' does not contain a definition for 'Parent'
Karthik Harve 29-Nov-11 6:53am    
replace with this..

ImageButton imgBtn = (ImageButton)(e.CommandSource);
GridViewRow gdvrow = (GridViewRow)(imgBtn.Parent.Parent);
string s = gdvrow.cells["HBL_NO"].Text;
Karthik Harve 29-Nov-11 6:53am    
replace with this..

ImageButton imgBtn = (ImageButton)(e.CommandSource);
GridViewRow gdvrow = (GridViewRow)(imgBtn.Parent.Parent);
string s = gdvrow.cells["HBL_NO"].Text;
If the error is about setting an instance value, then you should not focus on hbl_no.
Please first try to assign the value of "(ImageButton)sender).CommandName" like


C#
String cmdName = ((ImageButton)sender ).CommandName;
string s = gvBSV.SelectedRow.Cells[4].Text;
 Response.Redirect("Delivery_Order.aspx?BL_Code=" + cmdName + "&Purpose=N&Menu_ID=" + hndMenu_ID.Value +"&HBL_NO="+s.ToString());


then it will work fine.
 
Share this answer
 
v2
On row command
C#
protected void rcmd(object sender, GridViewCommandEventArgs e)
    {
        try
        {
            int index = Convert.ToInt32(e.CommandArgument);
            GridViewRow row = GridView1.Rows[index];

       lblReqID.Text = row.Cells[1].Text;//assign value of any cell by cell index

    }
catch()
{
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900