i want to get values from gridview row to textboxes and dropdowns when i select the particular row below is my asp code
i tried for selectedindex changing event of gridview but unable to call that event. do i miss any property?
please help?
asp code:
AutoGenerateColumns="False"
CssClass="grid_style" Width="550px"
onrowcreated="GridViewFeeType_RowCreated" AllowSorting="True"
onsorting="GridViewFeeType_Sorting"
onpageindexchanging="GridViewFeeType_PageIndexChanging" BackColor="White"
DataSourceID="SqlDataFeeType">
SortExpression="Fee_Type" >
SortExpression="Fee_Type_Desc">
SortExpression="Is_One_Time">
| Fee Type | Fee Description | Is One Time | |||
| No Data Found... |
cs code:
protected void GridViewstream_RowCreated(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
int row_index = e.Row.RowIndex + 1;
e.Row.Attributes.Add("onmouseover", "className='grid_row_mouse_over';");
e.Row.Attributes.Add("onmouseout", "className='grid_row_mouse_out'");
}
}
protected void GridViewstream_SelectedIndexChanging(object sender, GridViewSelectEventArgs e)
{
txtsub_strmname.Text = Convert.ToString(GridViewstream.SelectedRow.Cells[0].Text);
txtsub_strmcode.Text = Convert.ToString(GridViewstream.Rows[e.NewSelectedIndex].Cells[0].Text);
}
3 Replies
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Satyapriya NayakPosted Jun 6, 2012, 3:25 AM
Try this...
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Display_selected_records._Default" %>
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
namespace Display_selected_records
{
public partial class _Default : System.Web.UI.Page
{
string strConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
string str;
SqlCommand com;
SqlDataAdapter sqlda;
DataSet ds;
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
lbl_id.Text = GridView1.SelectedRow.Cells[1].Text;
lbl_name.Text = GridView1.SelectedRow.Cells[2].Text;
lbl_address.Text = GridView1.SelectedRow.Cells[3].Text;
lbl_marks.Text = GridView1.SelectedRow.Cells[4].Text;
lbl_year.Text = GridView1.SelectedRow.Cells[5].Text;
}
void bindgrid()
{
SqlConnection con = new SqlConnection(strConnString);
con.Open();
str = "select * from student";
com = new SqlCommand(str, con);
sqlda = new SqlDataAdapter(com);
ds = new DataSet();
sqlda.Fill(ds, "student");
GridView1.DataSource = ds;
GridView1.DataMember = "student";
GridView1.DataBind();
con.Close();
}
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
bindgrid();
}
}
}
}
Thanks
sameer gadadePosted Jun 14, 2012, 11:56 PM
sathish kumarPosted Jun 11, 2012, 7:48 AM
TRY OUT
ontextchanged="txtFloorCode_TextChanged" Height="24px" MaxLength="50"
ForeColor="#000099">
DataValueField="BuildingBlock" Height="24px" ForeColor="#000099">
SelectCommand="SELECT [BuildingBlock] FROM [BUILDING]">
Width="587px" AllowPaging="True" onrowcommand="gvFloor_RowCommand"
AutoGenerateColumns="False" ondatabound="gvFloorType_DataBound"
onprerender="gvFloorType_PreRender" ShowFooter="True"
EmptyDataText="No Records found !!" style="margin-left: 41px"
>
SelectCommand="SELECT [FloorCode], [FloorName],[BuildingBlock] FROM [FLOOR] Order By FloorName"
ProviderName="<%$ ConnectionStrings:CMC.ProviderName %>" >
protected void Display_Record(string strCode)
{
string strSQL;
string dbConn = ConfigurationManager.ConnectionStrings["CMC"].ConnectionString;
SqlConnection sqlConn = new SqlConnection(dbConn);
sqlConn.Open();
strSQL = "Select FloorName,BuildingBlock from [FLOOR] where FloorCode='" + txtFloorCode.Text + "' ";
SqlCommand cmdFloorType = new SqlCommand(strSQL, sqlConn);
SqlDataReader drFloor = cmdFloorType.ExecuteReader();
while (drFloor.Read())
{
txtFloorName.Text = drFloor[0].ToString();
DDLBuildingBlock.SelectedItem.Text = drFloor[1].ToString();
}
sqlConn.Close();
}
protected void gvBType_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "Select")
{
int index = Convert.ToInt32(e.CommandArgument);
GridViewRow gvRow = gvFloorType.Rows[index];
txtFloorCode.Text = Server.HtmlDecode(gvRow.Cells[1].Text);
Display_Record(txtFloorCode.Text);
}
this way will be very easier...the only thing you need to change is just index of cell...
Hope this code will help u.....