logo
down
shadow

Access gridview row's data from LinkButton inside that row


Access gridview row's data from LinkButton inside that row

Content Index :

Access gridview row's data from LinkButton inside that row
Tag : chash , By : Chris Woods
Date : November 27 2020, 09:01 AM

I wish did fix the issue. Possible solution would be as follows:
Add RowCreated and RowCommand events for GridView In RowCreated event, I have set “Visible” property to “false” for first column for both header and data row. In RowCommand event, CommandName is checked first and then index for select command is retrieved. I have retrieved the row for that index and then retrieved the text in the specified row cell.
protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.Header)
        {
            e.Row.Cells[0].Visible = false;
        }
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            e.Row.Cells[0].Visible = false;
        }
    }

    protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "Select")
        {
            int index = Convert.ToInt32(e.CommandArgument);
            GridViewRow row = GridView1.Rows[index];
            Label1.Text = (row.Cells[0].Text);
        }
    }
<asp:TemplateField HeaderText="Action3" Visible="false">
 <ItemStyle HorizontalAlign="Center"></ItemStyle>
 <ItemTemplate>
<asp:LinkButton ID="lnkretqty" runat="server" Text="Return Qty" CommandName="RETQTY" ToolTip="Click here to Add Return Qty Entry"
 CommandArgument='<%# Container.DataItemIndex %>'>
</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
Code Behind code

protected void gvsearch_RowCommand(object sender, GridViewCommandEventArgs e)
 {
 try
 {
 if (e.CommandName == "SRCSELREC")
 {
Int32 rowind = Convert.ToInt32(e.CommandArgument.ToString());
string val = ((Label)gvgpitemdtl.Rows[rowind].FindControl("d")).Text.ToString();


 }
}
catch (Exception ex)
 {
 General.MessageBox(this.Page, "Error at Gridview Row Command : " + ex.Message.ToString());
 return;
 }
}

Comments
No Comments Right Now !

Boards Message :
You Must Login Or Sign Up to Add Your Comments .

Share : facebook icon twitter icon

asp:linkbutton inside gridview


Tag : asp.net , By : 40a
Date : March 29 2020, 07:55 AM
I wish did fix the issue. You have a few of options:
The most common would be to assign a custom class or attribute to the button that you can use as a selector.

Full postback triggered by LinkButton inside GridView inside UpdatePanel


Tag : chash , By : Erik
Date : March 29 2020, 07:55 AM
will help you You need to register each and every LinkButton as an AsyncPostBackTrigger. After each row is bound in your GridView, you'll need to search for the LinkButton and register it through code-behind as follows:
protected void OrderGrid_RowDataBound(object sender, GridViewRowEventArgs e)  
{  
   LinkButton lb = e.Row.FindControl("MarkAsCompleteButton") as LinkButton;  
   ScriptManager.GetCurrent(this).RegisterAsyncPostBackControl(lb);  
}  

Linkbutton inside a gridview not firing


Tag : chash , By : Dave
Date : March 29 2020, 07:55 AM
it fixes the issue You have to use the GridView RowCommand event instead of the GridView SelectedIndex Change.. e.g
protected void gvBlockUnblock_RowCommand(object sender, GridViewCommandEventArgs e)
{
    if (e.CommandName == "Select")
    {

string ComplaintProfileId = gvBlockUnblock.DataKeys[gvBlockUnblock.SelectedIndex].Values["CPID"].ToString();
    string ISPUBLISHED = gvBlockUnblock.DataKeys[gvBlockUnblock.SelectedIndex].Values["PUBLISHED"].ToString();

    string date = System.DateTime.Now.ToString();
    TextBox tb = (TextBox)gvBlockUnblock.Rows[gvBlockUnblock.SelectedIndex].FindControl("txtAdminComment");
    string Comment = tb.Text;
    if (string.IsNullOrEmpty(Comment))
    {

        WebMsgBox.Show("empty");
    }
    else
    {
        if (ISPUBLISHED == "N")
        {
            ISPUBLISHED = "N";
        }
        else
        {
            ISPUBLISHED = "Y";
        }
        string AdminComment = (System.DateTime.Now.ToString() + " :  " + Comment);

        AddCommentBLL.InsertComment(AdminComment, ComplaintProfileId, ISPUBLISHED);
        gvBlockUnblock.DataSource = AddCommentBLL.GetItem();
        gvBlockUnblock.DataBind();
    }
    }
}
    protected void Page_Load(object sender, EventArgs e)
    {
     if(!IsPostBack)
     {
        // gets the items table using stored proc GetItem
        gvBlockUnblock.DataSource = AddCommentBLL.GetItem();
        gvBlockUnblock.DataBind();
        // used for paging
        Session["MyDataSett"] = gvBlockUnblock.DataSource;
     }
   }

How do I parse value from linkbutton inside gridview


Tag : chash , By : Scott Everts
Date : March 29 2020, 07:55 AM
it should still fix some issue You just have to cast the sender to LinkButton and use it's Text property:
protected void btnBatchId_Click(object sender, EventArgs e)
{
    LinkButton link = (LinkButton) sender;
    string batchID = link.Text;
}

how to bind gridview using Json by onclick event of Linkbutton inside other Gridview?


Tag : chash , By : Nougat
Date : March 29 2020, 07:55 AM
To fix the issue you can do I am binding Gridview using json (first Gridview),which have some column with linkbutton.
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.Web.Script.Services.ScriptService]
public class StudentWebService : System.Web.Services.WebService {

    public StudentWebService () {

        //Uncomment the following line if using designed components 
        //InitializeComponent(); 
    }

    [WebMethod]
    public DataTable GetStudents()
    {
        string constr = @"Server=WAQAS\SQLEXPRESS; Database=SampleDB; uid=sa; pwd=123";
        string query = "SELECT ID, Name, Fee FROM Students";
        SqlDataAdapter da = new SqlDataAdapter(query, constr);
        DataTable table = new DataTable();
        da.Fill(table);
        return table;
    }

    [WebMethod]    
    public int UpdateStudent(int id, string name, decimal fee)
    {
        SqlConnection con = null;
        string constr = @"Server=WAQAS\SQLEXPRESS; Database=SampleDB; uid=sa; pwd=123";
        string query = "UPDATE Students SET Name = @Name, Fee = @Fee WHERE ID = @ID";

        con = new SqlConnection(constr);
        SqlCommand command = new SqlCommand(query, con);
        command.Parameters.Add("@Name", SqlDbType.NVarChar).Value = name;
        command.Parameters.Add("@Fee", SqlDbType.Decimal).Value = fee;
        command.Parameters.Add("@ID", SqlDbType.Int).Value = id;

        int result = -1;
        try
        {
            con.Open();
            result = command.ExecuteNonQuery();
        }
        catch (Exception)
        { }
        finally
        {
            con.Close();
        }
        return result;
    }    
}
Related Posts Related QUESTIONS :
  • WPF XAML - Design time and visibility of textbox
  • EF Core and MySql query is too slow
  • Getting Registered App Display Name from an App Id
  • How to get all variables from a string
  • Delete entity with all childs connected
  • Azure Build agent cant´t find class library referance
  • Initialize Nested Dictionaries in c#
  • .Net Core Binding
  • Generic event test method, preventing code duplication
  • How do I keep the ellipses in the center when the screen is resized
  • How to require a property using JsonSchema.NET?
  • C# XDocument Element/Elements returns null
  • Autofac keyed service with IEnumerable relationship type
  • Installing EntityFramework via NuGet manager
  • Always Check if there is Internet Connection Xamarin forms
  • WCF OneWay service slows down when aspNetCompatibilityEnabled is set to false
  • Can we use JsonRequestBehavior.AllowGet with [HttpPost] attribute?
  • How to customize the Setup wizard with custom forms in Visual Studio setup project
  • C# ASP.NET - Use method from another class to create labels
  • C# List IList or IEnumerable as argument
  • Parsing File with C# And Replace method
  • Losing special unicode characters in encryption (C#)
  • Getting stored procedure returned value instead of row affected
  • How can I construct HTML using NameValuePair in android?
  • Loading a pop up page in ASP.net through a js file
  • How to pass alert or notification message from controller to View?
  • C# to pause, turn on ssas server, backup cube.... how to?
  • How to execute DataTable.Select() for a column of custom class type for a particular element in that C#
  • how to connect mysql8.0 with C#
  • Passing incorrect values into MultiValueConverter by MultiBinding
  • Can i use IEnumerator as Update func?
  • How to convert API Json response to C# Array?
  • Blazor Textfield Oninput User Typing Delay
  • Performing both layout and render transform results in wrong output
  • uwp beforetextchanged cursor moving in front of text
  • How to keep duplicates from a string[] exclude words from a List and print them out
  • .Net Core Strings.Asc/Mid/Chr/Len missing even after importing Microsoft.VisualBasic
  • How to return to previous search page without being asked to Confirm Form Re-submission and keeping the results on ASP.N
  • How set a identity scaffolding item/page how initial page in asp.net MVC core?
  • LINQ isn't calling Dispose on my IEnumerator when using Union and Select, expected behavior or bug?
  • What is "ByteArray.uncompress()" in AS3 equivalent to in C#?
  • Getting a specific letter from a string variable for my simple guessing game for clues
  • Send an email with Outlook without a subject --- dialog box issue
  • passing List<MyModel> from my controller in the "WebInterfaceProject" to the processor method in "D
  • How to convert Word document created from template by OpenXML into MemoryStream?
  • How can I make a single slider that changes the color of an object?
  • Remap JSON parameter in c#
  • What is the difference between "this ref" and "ref this" when talking about C# 7.2 ref extension met
  • Convert OpenSSL encryption into native C#
  • Accessing Properties in Razor Pages
  • How to get SOAP element value
  • Projection after Group
  • C# error cannot convert sytem.text.regularexpressions.match to string
  • Issues with Save/Load System in a Text Based Adventure game made with ScriptableObjects in Unity
  • VS2019 MSBuild.exe - ASP .Net MVC project fails to publish when using PublishProfile, but works when using OutDir parame
  • Does <pages validateRequest="false" /> in Web.config still matter?
  • How to send new request to redirect URL with new access token
  • Attempt to invoke virtual method on a null object reference Xamarin LockScreen
  • "The attribute names could not be inferred from bind attribute 'bind-value'" exception in Blazor
  • How to fix ''System.ArgumentException" in c#?
  • shadow
    Privacy Policy - Terms - Contact Us © scrbit.com