Click here to Skip to main content
15,890,845 members
Home / Discussions / ASP.NET
   

ASP.NET

 
Questionhow can we add rows to a grid view and maintain data in it Pin
samerh18-Feb-08 3:01
samerh18-Feb-08 3:01 
AnswerRe: how can we add rows to a grid view and maintain data in it Pin
ToddHileHoffer18-Feb-08 8:53
ToddHileHoffer18-Feb-08 8:53 
Generalpass variable from gridview to next page Pin
eyeseetee18-Feb-08 2:34
eyeseetee18-Feb-08 2:34 
GeneralRe: pass variable from gridview to next page Pin
Imran Khan Pathan18-Feb-08 2:38
Imran Khan Pathan18-Feb-08 2:38 
GeneralRe: pass variable from gridview to next page Pin
eyeseetee18-Feb-08 3:12
eyeseetee18-Feb-08 3:12 
GeneralRe: pass variable from gridview to next page Pin
eyeseetee18-Feb-08 3:35
eyeseetee18-Feb-08 3:35 
QuestionZip file Download problem.. Pin
rain raj18-Feb-08 2:33
rain raj18-Feb-08 2:33 
QuestionSorting changed it's order when click edit button and go to next page through paging ! Pin
sahoo.satya198418-Feb-08 2:29
sahoo.satya198418-Feb-08 2:29 
I can sort a column on the first page,but when i go to second page through paging sorting changed it's order.
Another problem is When i click Edit button,sorting is changed as a result data are also changed for which i can't edit the actual row rather i see a different data on the same row to be updated.

Here is my code...

<asp:GridView ID="GridView1" runat="server" AllowPaging="True" AllowSorting="True"
OnPageIndexChanging="pagemethod" OnSorting="sortmethod" OnRowEditing="editmethod"
AutoGenerateColumns="False" PageSize="4" >

<Columns>
<asp:CommandField HeaderText="Edit" ShowEditButton="True" ButtonType="Button" />

<asp:TemplateField HeaderText="Name" SortExpression="Name">

<ItemTemplate><%#Eval("Name")%></ItemTemplate>

<EditItemTemplate>
<asp:TextBox ID="txtname" runat="server" Text='<%# Eval("Name") %>'></asp:TextBox>
</EditItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>

protected void Page_Load(object sender, EventArgs e)

{
if (!IsPostBack)
{
BindGridView();
}

}

public void BindGridView()

{
DataSet ds = new DataSet();
ds=binddata();
GridView1.DataSource = ds;
GridView1.DataBind();
}

public DataSet binddata()

{
SqlConnection con = new SqlConnection("Server=.;database=emp;uid=sa;pwd=;");
SqlDataAdapter da = new SqlDataAdapter("select * from job", con);
con.Open();
DataSet ds = new DataSet();
da.Fill(ds, "emp");
return ds;
}



public void sortmethod(object sender, GridViewSortEventArgs e)

{
ViewState["sortcolumn"] = e.SortExpression;

if (ViewState["sortorder"] == null)
{
ViewState["sortorder"] = "asc";
}
ViewState["sortorder"]=ViewState["sortorder"].ToString() == "asc"?"desc":"asc";

DataView dv = new DataView(binddata().Tables[0]);
dv.Sort = ViewState["sortcolumn"] + " " + ViewState["sortorder"];
GridView1.DataSource = dv;
GridView1.DataBind();
}


public void pagemethod(object sender, GridViewPageEventArgs e)

{
GridView1.PageIndex = e.NewPageIndex;
GridView1.EditIndex = -1;
BindGridView();

}

public void editmethod(object sender, GridViewEditEventArgs e)

{
GridView1.EditIndex = e.NewEditIndex;
BindGridView();


}
GeneralRe: Sorting changed it's order when click edit button and go to next page through paging ! Pin
Imran Khan Pathan18-Feb-08 2:35
Imran Khan Pathan18-Feb-08 2:35 
Questionhow to do Edit,Update and Insert in DetailsView ? Pin
mahmoud wafy18-Feb-08 2:16
mahmoud wafy18-Feb-08 2:16 
AnswerRe: how to do Edit,Update and Insert in DetailsView ? Pin
J a a n s18-Feb-08 5:02
professionalJ a a n s18-Feb-08 5:02 
Generalcache problem Pin
hsch2918-Feb-08 2:16
hsch2918-Feb-08 2:16 
GeneralChange visibility of control after download Pin
Krugger40418-Feb-08 2:07
Krugger40418-Feb-08 2:07 
GeneralRe: Change visibility of control after download Pin
Mircea Puiu18-Feb-08 5:19
Mircea Puiu18-Feb-08 5:19 
GeneralGridview variable Pin
eyeseetee18-Feb-08 1:29
eyeseetee18-Feb-08 1:29 
Generaltreeview Pin
niki_nilu18-Feb-08 1:14
niki_nilu18-Feb-08 1:14 
Questionmessage box in asp.net Pin
Sonia Gupta18-Feb-08 0:57
Sonia Gupta18-Feb-08 0:57 
GeneralRe: message box in asp.net Pin
Imran Khan Pathan18-Feb-08 1:03
Imran Khan Pathan18-Feb-08 1:03 
GeneralRe: message box in asp.net Pin
Bluebamboo18-Feb-08 1:06
Bluebamboo18-Feb-08 1:06 
GeneralConvert html to image Pin
Imran Khan Pathan18-Feb-08 0:51
Imran Khan Pathan18-Feb-08 0:51 
GeneralRe: Convert html to image Pin
soni uma18-Feb-08 0:58
soni uma18-Feb-08 0:58 
Generalradiobuttonlist and asp.net2.0 Pin
ritu432118-Feb-08 0:46
ritu432118-Feb-08 0:46 
GeneralRe: radiobuttonlist and asp.net2.0 Pin
Imran Khan Pathan18-Feb-08 0:53
Imran Khan Pathan18-Feb-08 0:53 
GeneralRe: radiobuttonlist and asp.net2.0 Pin
ritu432118-Feb-08 1:04
ritu432118-Feb-08 1:04 
GeneralRe: radiobuttonlist and asp.net2.0 Pin
soni uma18-Feb-08 1:08
soni uma18-Feb-08 1:08 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.