link button using in gridview another page redirect how?

Posted by Chandru_ra under Regular Expressions on 3/23/2011 | Points: 10 | Views : 32016 | Status : [Member] | Replies : 1
Dear all,

design page:

<asp:GridView>
<Columns>
<asp:TemplateField HeaderText="university/Board">
<ItemTemplate>
<asp:LinkButton CommandName="cmdBind" runat="server" Text='<%#Eval("UnivName")%>' ID="hypeno" CommandArgument='<% #Bind("UnivName") %>'>LinkButton
</asp:LinkButton>

</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>



protected void Gridquestionpaper_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "cmdBind")
{
string UnivID = e.CommandArgument.ToString();
LinkButton lb = (LinkButton)e.CommandSource;

Response.Redirect("Universitydetails.aspx?UnivID="+UnivID);
}
}

ANOTHER PAGE: UnivID is primarykey is also used in this table..fetch by another table univname how?

protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
GetUniversitydetail();
}
}
public void GetUniversitydetail()
{
SqlConnection con = new SqlConnection(strCS);
SqlDataAdapter da = new SqlDataAdapter("select * from tblUniversity where UnivID='" + Request.QueryString["UnivID"].ToString() + "'", con);
DataSet ds = new DataSet();
da.Fill(ds);
GridView1.DataSource = ds;
GridView1.DataBind();
}

chandru


Responses

Posted by: SheoNarayan on: 3/23/2011 [Administrator] HonoraryPlatinum | Points: 25

Up
0
Down
asp:LinkButton control also has the PostBackUrl you can set, eg.

<asp:LinkButton runat="server" PostBackUrl='Universitydetails.aspx?UnivID=<%# Eval("UnivId") %>'  Text='<%#Eval("UnivName")%>'></asp:LinkButton>


In this way, you do not need to raise a server side event and redirect to another page, When user clicks on the button, he/she will be directly posted back to Universitydetails.aspx page.

Hope this helps.

Regards,
Sheo Narayan
http://www.dotnetfunda.com

Chandru_ra, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response