How to get the values of the particular row of the gridview when it is clicked? [Resolved]

Posted by .Netlearner under ASP.NET on 6/5/2012 | Points: 10 | Views : 912 | Status : [Member] | Replies : 3
Hello All,

Am having a gridview control which is loaded dynamically from the database.I want the data of the particular row of the gridview when the particular row is clicked to display in the textboxes.I dont know how this can be done.kindly guide me.




Responses

Posted by: Ajay.Kalol on: 6/6/2012 [Member] Starter | Points: 50

Up
0
Down

Resolved
Declare SelectIndexChanged event of GridView and then write this code inside it :

 Protected Sub gvPackage_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles gvPackage.SelectedIndexChanged

Try
lblPackageID.Text = gvPackage.SelectedRow.Cells(1).Text 'Assign the value of cell to the textField
txtPackage.Text = gvPackage.SelectedRow.Cells(2).Text 'Assign the value of cell to the textField
txttenure.Text = gvPackage.SelectedRow.Cells(3).Text 'Assign the value of cell to the textField
txtDescription.Text = gvPackage.SelectedRow.Cells(4).Text
txtPkgPrice.Text = gvPackage.SelectedRow.Cells(5).Text

Catch ex As Exception

End Try
End Sub



Enjoy....

Ajay
ajaypatelfromsanthal.blogspot.in

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

Posted by: .Netlearner on: 6/6/2012 [Member] Starter | Points: 25

Up
0
Down
Thanks a lot . . It worked

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

Posted by: perfectchourasia-9163 on: 6/8/2012 [Member] Starter | Points: 25

Up
0
Down
<asp:Label ID="lblstatus" Visible="false" runat="server" Text='<%# Eval("status") %>'></asp:Label>
<asp:Button ID="btnStatus" CssClass="btn" runat="server" CausesValidation="false"
CommandName="CommandStatus" Text='<%#Eval("staus1")%>' CommandArgument='<%#Eval("ArticleID")%>'
OnClientClick="return ConfirmStatus()" />


on row cammand

else if (e.CommandName == "CommandStatus")
{
int index = Convert.ToInt32(e.CommandArgument.ToString());
GridViewRow row = (GridViewRow)(((Button)e.CommandSource).NamingContainer);
Label staus = (Label)row.Cells[9].FindControl("lblstatus");

try
{
string Squery = string.Empty;
if (staus.Text.ToString().Trim() == "0")
{
Squery ="update tblArticleMasterArticles set status ='1' where articleid=" + index;
}
else
{
Squery = "update tblArticleMasterArticles set status ='0' where articleid=" + index;
}
SqlHelper.ExecuteNonQuery(ConnectionString, CommandType.Text, Squery);
Fillgridview();
lblMsg.Text = "Status Changed Successfully.";

}
catch (Exception ex)
{

}


ER sandeep chourasia
sandeepchrs@yahoo.com (on facebook)
http://www.aspnetcodes.com/

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

Login to post response